Skip to content

Commit

Permalink
fix: cohere editor status visualization slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-he committed Jul 1, 2024
1 parent ab30a22 commit ec57d71
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
45 changes: 31 additions & 14 deletions internal/ui/panes/composite_editor_ui_pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,11 @@ func (p *CompositeEditorPane) Draw() {
x, y, w, h := p.Dims()

// draw background
style := p.Stylesheet.Editor
status := p.e.GetStatus()
c := '?'
switch status {
case edit.EditorDescendantActive:
c = '.'
case edit.EditorFocussed:
c = '*'
case edit.EditorInactive:
c = ' '
case edit.EditorSelected:
c = '>'
}
style := getAlteredStyleForEditorStatus(p.Stylesheet.Editor, p.e.GetStatus())

p.Renderer.DrawBox(x, y, w, h, style)
p.Renderer.DrawText(x+1, y, w-2, 1, style, util.TruncateAt(p.e.GetName(), w-2))
p.Renderer.DrawText(x, y, 1, 1, style.Bolded(), string(c))
p.Renderer.DrawText(x, y, 1, 1, style.Bolded(), string(getRuneForEditorStatus(p.e.GetStatus())))

// draw all subpanes
for _, subpane := range p.subpanes {
Expand All @@ -58,6 +47,34 @@ func (p *CompositeEditorPane) Draw() {
}
}

func getRuneForEditorStatus(status edit.EditorStatus) rune {
switch status {
case edit.EditorDescendantActive:
return '.'
case edit.EditorFocussed:
return '*'
case edit.EditorInactive:
return ' '
case edit.EditorSelected:
return '>'
}
return '?'
}

func getAlteredStyleForEditorStatus(baseStyle styling.DrawStyling, status edit.EditorStatus) styling.DrawStyling {
switch status {
case edit.EditorInactive:
return baseStyle.LightenedBG(10)
case edit.EditorSelected:
return baseStyle
case edit.EditorDescendantActive:
return baseStyle.DarkenedBG(10)
case edit.EditorFocussed:
return baseStyle.DarkenedBG(20).Bolded()
}
return baseStyle
}

// Undraw ensures that the cursor is hidden.
func (p *CompositeEditorPane) Undraw() {
for _, subpane := range p.subpanes {
Expand Down
17 changes: 3 additions & 14 deletions internal/ui/panes/string_editor_ui_pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,19 @@ func (p *StringEditorPane) Draw() {
if p.IsVisible() {
x, y, w, h := p.Dims()

baseStyle := p.Stylesheet.Editor
status := p.e.GetStatus()
baseStyle := getAlteredStyleForEditorStatus(p.Stylesheet.Editor, status)
boxStyle := baseStyle
fieldStyle := baseStyle
labelStyle := baseStyle
status := p.e.GetStatus()
c := '?'
switch status {
case edit.EditorDescendantActive:
c = '.'
case edit.EditorFocussed:
c = '*'
case edit.EditorInactive:
c = ' '
case edit.EditorSelected:
c = '>'
}

nameWidth := 8
modeWidth := 5
padding := 1

p.Renderer.DrawBox(x, y, w, h, boxStyle)
p.Renderer.DrawText(x+padding, y, nameWidth, h, labelStyle, p.e.GetName())
p.Renderer.DrawText(x, y, 1, 1, boxStyle.Bolded(), string(c))
p.Renderer.DrawText(x, y, 1, 1, boxStyle.Bolded(), string(getRuneForEditorStatus(status)))

if status == edit.EditorFocussed {
switch p.e.GetMode() {
Expand Down

0 comments on commit ec57d71

Please sign in to comment.