Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
disable unfocus keymap
Browse files Browse the repository at this point in the history
  • Loading branch information
ingbyr committed Sep 6, 2022
1 parent 9a5eec2 commit 3eabbbd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
25 changes: 14 additions & 11 deletions tui/editor_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/textarea"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"gohost/config"
"gohost/gohost"
"os"
Expand All @@ -13,6 +14,7 @@ type EditorView struct {
model *Model
hostEditor textarea.Model
host gohost.Host
statusLine string
}

func NewTextView(model *Model) *EditorView {
Expand All @@ -21,6 +23,7 @@ func NewTextView(model *Model) *EditorView {
return &EditorView{
model: model,
hostEditor: hostEditor,
statusLine: "initializing",
}
}

Expand All @@ -39,31 +42,31 @@ func (v *EditorView) Init() tea.Cmd {
func (v *EditorView) Update(msg tea.Msg) []tea.Cmd {
var cmd tea.Cmd
var cmds []tea.Cmd
v.hostEditor, cmd = v.hostEditor.Update(msg)
cmds = append(cmds, cmd)
switch msg := msg.(type) {
switch m := msg.(type) {
case tea.WindowSizeMsg:
v.hostEditor.SetHeight(msg.Height - v.model.reservedHeight)
v.hostEditor.SetWidth(msg.Width - v.model.groupView.groupList.Width())
}
if v.model.state == editorViewState {
switch msg := msg.(type) {
case tea.KeyMsg:
v.hostEditor.SetHeight(m.Height - v.model.reservedHeight - 1)
v.hostEditor.SetWidth(m.Width - v.model.groupView.groupList.Width())
case tea.KeyMsg:
if v.model.state == editorViewState {
switch {
case key.Matches(msg, keys.Save):
case key.Matches(m, keys.Save):
v.host.SetContent([]byte(v.hostEditor.Value()))
err := gohost.GetService().UpdateHost(v.host)
if err != nil {
v.model.Log(err.Error())
}
}
} else {
// Disable key
msg = nil
}
}
v.hostEditor, cmd = v.hostEditor.Update(msg)
return append(cmds, cmd)
}

func (v *EditorView) View() string {
return v.hostEditor.View()
return lipgloss.JoinVertical(lipgloss.Top, v.hostEditor.View(), v.statusLine)
}

func (v *EditorView) Focus() {
Expand Down
17 changes: 9 additions & 8 deletions tui/group_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,15 @@ func (v *GroupView) Init() tea.Cmd {
func (v *GroupView) Update(msg tea.Msg) []tea.Cmd {
var cmd tea.Cmd
var cmds []tea.Cmd
v.groupList, cmd = v.groupList.Update(msg)
cmds = append(cmds, cmd)
switch msg := msg.(type) {
switch m := msg.(type) {
case tea.WindowSizeMsg:
v.groupList.SetHeight(msg.Height - v.model.reservedHeight)
v.groupList.SetWidth(msg.Width / 3)
v.model.helpView.debug = fmt.Sprintf("w %d h %d, w %d h %d", msg.Width, msg.Height, v.groupList.Width(), v.groupList.Height())
v.groupList.SetHeight(m.Height - v.model.reservedHeight)
v.groupList.SetWidth(m.Width / 3)
v.model.helpView.debug = fmt.Sprintf("w %d h %d, w %d h %d", m.Width, m.Height, v.groupList.Width(), v.groupList.Height())
case tea.KeyMsg:
if v.model.state == groupViewState {
switch {
case key.Matches(msg, keys.Enter):
case key.Matches(m, keys.Enter):
selectedItem := v.groupList.SelectedItem()
if selectedItem != nil {
v.selectedNode = selectedItem.(*gohost.Node[gohost.TreeNode])
Expand All @@ -110,9 +108,12 @@ func (v *GroupView) Update(msg tea.Msg) []tea.Cmd {
}
}
}
} else {
// Disable key
msg = nil
}
}

v.groupList, cmd = v.groupList.Update(msg)
return append(cmds, cmd)
}

Expand Down

0 comments on commit 3eabbbd

Please sign in to comment.