Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection of small enhancements #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,17 +671,26 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
case tcell.KeyF8:
app.win.ToggleMemberList()
case tcell.KeyCR, tcell.KeyLF:
if app.pasting {
app.win.InputRune('\n')
break
}
netID, buffer := app.win.CurrentBuffer()
input := string(app.win.InputContent())
if err := app.handleInput(buffer, input); err != nil {
app.win.AddLine(netID, buffer, ui.Line{
At: time.Now(),
Head: "!!",
HeadColor: tcell.ColorRed,
Notify: ui.NotifyUnread,
Body: ui.PlainSprintf("%q: %s", input, err),
})
} else {
errs := false
for _, part := range strings.Split(input, "\n") {
if err := app.handleInput(buffer, part); err != nil {
errs = true
app.win.AddLine(netID, buffer, ui.Line{
At: time.Now(),
Head: "!!",
HeadColor: tcell.ColorRed,
Notify: ui.NotifyUnread,
Body: ui.PlainSprintf("%q: %s", part, err),
})
}
}
if errs == false {
app.win.InputFlush()
}
case tcell.KeyRune:
Expand Down
38 changes: 26 additions & 12 deletions ui/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (e *Editor) End() {

func (e *Editor) Up() {
if e.autoCache != nil {
e.autoCacheIdx = (e.autoCacheIdx + 1) % len(e.autoCache)
e.autoCacheIdx = (e.autoCacheIdx + len(e.autoCache) - 1) % len(e.autoCache)
return
}
if e.lineIdx == 0 {
Expand All @@ -364,7 +364,7 @@ func (e *Editor) Up() {

func (e *Editor) Down() {
if e.autoCache != nil {
e.autoCacheIdx = (e.autoCacheIdx + len(e.autoCache) - 1) % len(e.autoCache)
e.autoCacheIdx = (e.autoCacheIdx + 1) % len(e.autoCache)
return
}
if e.lineIdx == len(e.text)-1 {
Expand All @@ -388,7 +388,9 @@ func (e *Editor) AutoComplete() (ok bool) {
return false
}
e.autoCacheIdx = 0
return
if len(e.autoCache) > 1 {
return
}
}

e.text[e.lineIdx] = e.autoCache[e.autoCacheIdx].Text
Expand Down Expand Up @@ -490,6 +492,10 @@ func (e *Editor) Draw(screen tcell.Screen, x0, y int, hint string) {
if i == autoStart {
autoX = x
}
if r == '\n' {
r = '↲'
s = s.Background(tcell.ColorRed).Foreground(tcell.ColorBlack)
}
screen.SetContent(x, y, r, nil, s)
x += runeWidth(r)
i++
Expand Down Expand Up @@ -521,28 +527,36 @@ func (e *Editor) Draw(screen tcell.Screen, x0, y int, hint string) {
}
}

pad_rune := rune(' ')
for i, completion := range e.autoCache[autoOff : autoOff+autoCount] {
display := completion.Display
if display == nil {
display = completion.Text[completion.StartIdx:]
}

x := autoX
y := y - i - 1
y := y - (autoCount - i)

s := st.Background(tcell.ColorBlack)
s = s.Reverse(i+autoOff == e.autoCacheIdx)

/* Pad one space at the left */
screen.SetContent(x, y, pad_rune, nil, s)
x += runeWidth(pad_rune)

for _, r := range display {
if x >= x0+e.width {
if x + 1 >= x0+e.width {
break
}
s := st.Background(tcell.ColorBlack)
s = s.Reverse(true)
if i+autoOff == e.autoCacheIdx {
s = s.Bold(true)
} else {
s = s.Dim(true)
}
screen.SetContent(x, y, r, nil, s)
x += runeWidth(r)
}

/* Pad to the right so we get to 20 in total */
for (x - autoX) < 20 && x < x0+e.width {
screen.SetContent(x, y, pad_rune, nil, s)
x += runeWidth(pad_rune)
}
}

if showCursor {
Expand Down
3 changes: 3 additions & 0 deletions ui/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
var condition = runewidth.Condition{}

func runeWidth(r rune) int {
if r == '\n' {
r = '↲'
}
return condition.RuneWidth(r)
}

Expand Down