Skip to content

Commit

Permalink
Crop text
Browse files Browse the repository at this point in the history
  • Loading branch information
Evertras committed Jan 28, 2024
1 parent 6196818 commit b5db89d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/command.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ layout:
config:
interval: 5s
bash: date
- name: Readme
- name: Makefile
module: command
style:
align-horizontal: left
align-vertical: top
config:
bash: cat README.md
bash: cat Makefile
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/evertras/yakdash
go 1.21.5

require (
github.com/charmbracelet/bubbles v0.17.1
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/mitchellh/mapstructure v1.5.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbles v0.17.1 h1:0SIyjOnkrsfDo88YvPgAWvZMwXe26TP6drRvmkjyUu4=
github.com/charmbracelet/bubbles v0.17.1/go.mod h1:9HxZWlkCqz2PRwsCbYl7a3KXvGzFaDHpYbSYMJ+nE3o=
github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM=
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
Expand Down
16 changes: 12 additions & 4 deletions pkg/panes/panes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package panes

import (
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
Expand All @@ -23,15 +24,18 @@ type Pane struct {

width int
height int

textarea viewport.Model
}

// NewModel creates a new pane containing the given model.
func NewLeaf(m tea.Model) Pane {
borderStyle := lipgloss.NewStyle().Border(lipgloss.RoundedBorder())

return Pane{
model: m,
style: borderStyle.Align(lipgloss.Center, lipgloss.Center),
model: m,
style: borderStyle.Align(lipgloss.Center, lipgloss.Center),
textarea: viewport.New(0, 0),
}
}

Expand Down Expand Up @@ -88,10 +92,14 @@ func (m Pane) Update(msg tea.Msg) (Pane, tea.Cmd) {
func (m Pane) View() string {
if m.model != nil {
style := m.style.Copy().Width(m.width - 2).Height(m.height - 2)
m.textarea.Width = m.width - 2
m.textarea.Height = m.height - 2
m.textarea.SetContent(m.model.View())
innerView := m.textarea.View()
if m.name != "" {
return m.genTop() + "\n" + style.Render(m.model.View())
return m.genTop() + "\n" + style.Render(innerView)
}
return style.Render(m.model.View())
return style.Render(innerView)
}

childrenViews := make([]string, len(m.children))
Expand Down

0 comments on commit b5db89d

Please sign in to comment.