Skip to content

Commit

Permalink
handle past with Ctrl+v input fix some error deletted and rename
Browse files Browse the repository at this point in the history
  • Loading branch information
waxdred committed Jan 27, 2023
1 parent 559ac32 commit 056d6c6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Binary file modified bin/chatGPT
Binary file not shown.
12 changes: 11 additions & 1 deletion models.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(tiCmd, vpCmd, spCmd, reCmd)
}
switch msg.String() {
case "ctrl+v":
if m.prompt {
clip, err := clipboard.ReadAll()
if err != nil {
return m, nil
}
value := m.textarea.Value() + clip
m.textarea.SetValue(value)
}
case "ctrl+y":
if m.last_answer != "" {
clipboard.WriteAll(m.last_answer)
Expand Down Expand Up @@ -361,6 +370,7 @@ func (m model) View() string {
rename = m.textinput.View()
} else {
rename = StyleUTF + StyleCreate
rename = StylehelperLoader.Render(rename)
}
if m.session {
ret = lipgloss.JoinVertical(
Expand All @@ -378,7 +388,7 @@ func (m model) View() string {
} else {
ret = lipgloss.JoinVertical(lipgloss.Top,
ret,
status+StylehelperValue.Render("")+StylehelperLoader.Render(rename))
status+StylehelperValue.Render("")+rename)
}
return ret
}
4 changes: 2 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s Sessions) rename(rename string, idx int64) error {
news := rename + ".json"
session := Session{}
for i, se := range s {
if i+1 == int(idx) {
if i == int(idx)-1 {
session = se
}
}
Expand All @@ -94,7 +94,7 @@ func (s Sessions) deleteFile(idx int) Sessions {
var tmp []Session
for i, se := range s {
if i+1 == idx {
name := strings.Replace(se.Created_at, " ", "", -1)
name := strings.Replace(se.Title, " ", "", -1)
filename := Path + name + ".json"
os.Remove(filename)
} else {
Expand Down
4 changes: 3 additions & 1 deletion style.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ var (
Height(1).Width(WeightChat - 5)
StylehelperLoader = lipgloss.NewStyle().Background(lipgloss.Color(purple)).
Height(1).Width(WeightSet)
StylehelperLoaderRename = lipgloss.NewStyle().
Height(1).Width(WeightSet)
colorHelper = lipgloss.NewStyle().Foreground(lipgloss.Color(greyHelper))
Stylehelper = lipgloss.NewStyle().Foreground(lipgloss.Color(grey)).MarginLeft(2)
helperInput = colorHelper.Render(" <C-n>: new Session <C-y>: copy <Tab>: Cycle over windows")
helperInput = colorHelper.Render(" <C-n>: new Session <C-y>: copy <C-v>: past")
helperSetting = colorHelper.Render(" <C-k>: up <C-j>: down (+/-)")
helperSession = colorHelper.Render(" <C-k>: up <C-j>: down <C-r>: rename <C-d>: delete")
errorApi = "Error OPENAI_API_KEY env missing:\nadd OPENAI_API_KEY=<api> to your env\nfor get your api:\nhttps://beta.openai.com/account/api-keys"
Expand Down

0 comments on commit 056d6c6

Please sign in to comment.