Emily French, 21, told the High Court in Glasgow that while she was at a house in Peebles with Nicholas Rogers and Alex Stuart on the night of the latter’s death, she spoke to the former for over an hour.
The 27-year-old later stabbed Alex to death in the town’s Cuddyside on August 6 last year.
Rogers is on trial charged with murdering her.
The former customer services worker admits killing the 22 year-old but claims he was suffering from an “abnormality of the mind” at the time.
Miss French was asked if she had spoken to Rogers and she replied that they had talked for over an hour in the house’s kitchen and that others were coming in and out of the room.
Advocate depute Keith Stewart asked what they were talking about, and Miss French said: “He said he was upset about himself.
“He said he didn’t feel worthy to be on earth.
“He said he would like to kill himself.”
She told the court that afterwards they went into the house’s living room and sat chatting.
Asked what they were talking about in the kitchen, Miss French said: “He was upset and distressed. He was talking about his childhood and his depression.”
The court heard that he told Miss French he had been in the Huntlyburn Ward at the Borders General Hospital in Melrose and said he didn’t want to go back although he still felt depressed.
She said: “I was trying to help him and calm him down. I kept saying tomorrow is another day.
“I was saying there’s a whole world out there, and you can do what you want with your life.”
Defence barrister Brian McConnachie asked if Rogers told her he had taken an overdose a week earlier and she confirmed that he had.
Earlier in proceedings, Rogers was said to have asked police: “Why did I do it?”
Rogers was held following a struggle outside the Tesco supermarket in Peebles last August 6, and it was claimed that he threatened to kill one of the officers arresting him.
However, jurors heard, he later directed police to where the fatal attack was carried out and told them: “I am going to jail.”
PC Barry Haig was one of the officers called to the supermarket and saw Rogers apparently having a row with his then girlfriend, Katrina Kelly, 19.
Rogers was described as “very agitated and angry”.
He was then said to have stated: “I stabbed her,” and when asked who, he added: “Alex.”
PC Haig told prosecutor Keith Stewart that Rogers asked him: “Why did I do it? I am going to jail. I stabbed her. I don’t want her to die. I wish I had never done it.”
Sergeant Ross Falconer was the first officer to arrive at the Dovecot Road Tesco store and was told by Miss Kelly: “He is going crazy. He needs sectioned.”
Sgt Falconer approached Rogers and tried to calm him down but to no avail.
The officer recalled: “Immediately on placing hands on him, he became aggressive.
“He said ‘take your hands off me. If you don’t take your f*****g hands off me, I will kill you.”
Miss Kelly told the court she and Rogers had started dating in August 2016 and soon became aware that he had personal problems including mental health difficulties, as well as gambling and alcohol issues.
Mr Stewart asked her: “Did he ever say to you ‘who do you want sacrificed?’.”
The teenager replied: “He did, yes. It was a text message. I asked what he was on about.”
Rogers was also said to have described himself as a “broken toy that cannot be fixed”.
On the night of Alex’s killing, Rogers asked Miss Kelly to take him to Peebles in the early hours as he wanted to have a drink with people he was not “emotionally attached” to.
He later contacted her to ask to be picked up and as she tried to find him, Miss Kelly recalled him stating: “I think I have killed someone. You have to come and get me.”
Rogers thrust a knife into Alex’s chest as she sat crying on a couch, the court heard last week.
Rogers was said to have armed himself with a blade after claiming he was a “hard man” and a “bad person”.
Alex’s friend Rebecca Allen, a hairdresser, was the first witness to testify and she recounted how the pair, and others, visited several bars before ending up at a house party.
Miss Allen said Rogers then also appeared, and he was drinking from a bottle of gin.
Miss Allen, 27, told jurors she felt uncomfortable as Rogers started acting increasingly strangely, saying: “I did not get good vibes.”
Rogers later emerged from the kitchen holding a knife.
Miss Allen recalled: “He walked over, and I said ‘what is going on?’.
“He said ‘you are not laughing now, are you?’. I told him ‘no one is laughing at you’.”
The court heard he kicked a table and pointed the blade at her, Alex and another man.
Miss Allen said: “I was trying to reason with him, but it was not working. Alex was in total shock.
“She was sitting with her knees up, staring at me crying. He was scraping the knife at Alex’s legs, taunting her. It was like a power thing.”
Rogers is said to have then stated: “I have f****d it now – I may as well kill somebody.”
Miss Allen told the court: “I said there was no need for this. I kept saying that I wanted to get home for my wee girl.
“He said ‘there is no point. You will tell on me. I am going to jail anyway’.”
Miss Allen then watched as Rogers knifed Alex, recalling: “He just went in a downwards action and stabbed Alex right in the chest.
“I heard it too. I stood up and tried to push him away as he was trying to take it back out of her.
“He then grabbed my face and smacked my head against the wall.”
Miss Allen said Rogers then stopped and walked out the door.
She went on: “I had to go over and check she was OK. I could see the colour fading from her face.
“She did not make a noise for about three minutes. I tried to keep her awake. There is nothing that I could have done.”
Alex died later that day in Edinburgh Royal Infirmary.
Rogers’ trial, before judge Lord Alan Summers, continues.