-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package reddit | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/azimut/cli-view/internal/tui" | ||
tea "github.com/charmbracelet/bubbletea" | ||
) | ||
|
||
const rightPadding = 10 | ||
|
||
type Model struct { | ||
render tui.Model | ||
Thread | ||
} | ||
|
||
func NewProgram(thread Thread) *tea.Program { | ||
return tea.NewProgram(Model{Thread: thread}, | ||
tea.WithAltScreen()) | ||
} | ||
|
||
func (m Model) Init() tea.Cmd { | ||
return nil | ||
} | ||
|
||
func (m Model) View() string { | ||
return m.render.View() | ||
} | ||
|
||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
var cmd tea.Cmd | ||
m.render, cmd = m.render.Update(msg) | ||
switch msg := msg.(type) { | ||
case tea.WindowSizeMsg: | ||
m.Width = 200 | ||
m.render.RawContent = fmt.Sprint(m) | ||
m.Width = uint(msg.Width) - rightPadding | ||
m.render.Viewport.SetContent(fmt.Sprint(m)) | ||
} | ||
return m, cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters