Skip to content

Commit

Permalink
fix(split-editors): resize issue
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Aug 18, 2022
1 parent 4e9a56f commit a7f50a6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions examples/split-editors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
initialInputs = 2
maxInputs = 6
minInputs = 1
helpHeight = 5
)

var (
Expand Down Expand Up @@ -44,7 +45,6 @@ type keymap = struct {

func newTextarea() textarea.Model {
t := textarea.New()
t.SetHeight(20)
t.Prompt = ""
t.Placeholder = "Type something"
t.ShowLineNumbers = true
Expand All @@ -63,6 +63,7 @@ func newTextarea() textarea.Model {

type model struct {
width int
height int
keymap keymap
help help.Model
inputs []textarea.Model
Expand Down Expand Up @@ -144,6 +145,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
case tea.WindowSizeMsg:
m.height = msg.Height
m.width = msg.Width
}

Expand All @@ -163,6 +165,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *model) sizeInputs() {
for i := range m.inputs {
m.inputs[i].SetWidth(m.width / len(m.inputs))
m.inputs[i].SetHeight(m.height - helpHeight)
}
}

Expand All @@ -189,7 +192,7 @@ func (m model) View() string {
}

func main() {
if err := tea.NewProgram(newModel()).Start(); err != nil {
if err := tea.NewProgram(newModel(), tea.WithAltScreen()).Start(); err != nil {
fmt.Println("Error while running program:", err)
os.Exit(1)
}
Expand Down

0 comments on commit a7f50a6

Please sign in to comment.