|
@@ -67,47 +67,66 @@ func (m Model) Init() tea.Cmd { return m.load }
|
|
|
|
|
|
|
|
// Handles quit logic and viewport scroll and size updates
|
|
// Handles quit logic and viewport scroll and size updates
|
|
|
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
|
|
+ // widget specifc keyhandling
|
|
|
|
|
+ switch m.widget.(type) {
|
|
|
|
|
+ case issueCreate:
|
|
|
|
|
+ if msg, ok := msg.(tea.KeyMsg); ok {
|
|
|
|
|
+ switch msg.String() {
|
|
|
|
|
+ case "enter": // TODO create, write, and render an issue on press enter
|
|
|
|
|
+ return m, tea.Quit
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ default:
|
|
|
|
|
+ if msg, ok := msg.(tea.KeyMsg); ok {
|
|
|
|
|
+ switch msg.String() {
|
|
|
|
|
+ case "q":
|
|
|
|
|
+ return m, tea.Quit
|
|
|
|
|
+ case "j":
|
|
|
|
|
+ if collection, ok := m.widget.(IssueCollection); ok {
|
|
|
|
|
+ if collection.selection+1 < len(collection.Collection) {
|
|
|
|
|
+ collection.selection = collection.selection + 1
|
|
|
|
|
+ } else {
|
|
|
|
|
+ collection.selection = 0
|
|
|
|
|
+ }
|
|
|
|
|
+ m.widget = collection
|
|
|
|
|
+ return m, collection.view
|
|
|
|
|
+ }
|
|
|
|
|
+ return m, nil
|
|
|
|
|
+ case "k":
|
|
|
|
|
+ // do something only if widget is collection
|
|
|
|
|
+ if collection, ok := m.widget.(IssueCollection); ok {
|
|
|
|
|
+ if collection.selection != 0 {
|
|
|
|
|
+ collection.selection = collection.selection - 1
|
|
|
|
|
+ } else {
|
|
|
|
|
+ collection.selection = len(collection.Collection) - 1
|
|
|
|
|
+ }
|
|
|
|
|
+ m.widget = collection
|
|
|
|
|
+ return m, collection.view
|
|
|
|
|
+ }
|
|
|
|
|
+ return m, nil
|
|
|
|
|
+ case "enter":
|
|
|
|
|
+ if _, ok := m.widget.(IssueCollection); ok {
|
|
|
|
|
+ m.Path = m.widget.(IssueCollection).Collection[m.widget.(IssueCollection).selection].Path
|
|
|
|
|
+ return m, m.load
|
|
|
|
|
+ }
|
|
|
|
|
+ return m, nil
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
switch msg := msg.(type) {
|
|
switch msg := msg.(type) {
|
|
|
case tea.KeyMsg:
|
|
case tea.KeyMsg:
|
|
|
switch msg.String() {
|
|
switch msg.String() {
|
|
|
- case "q":
|
|
|
|
|
|
|
+ case "ctrl+c":
|
|
|
return m, tea.Quit
|
|
return m, tea.Quit
|
|
|
- case "j":
|
|
|
|
|
- if collection, ok := m.widget.(IssueCollection); ok {
|
|
|
|
|
- if collection.selection+1 < len(collection.Collection) {
|
|
|
|
|
- collection.selection = collection.selection + 1
|
|
|
|
|
- } else {
|
|
|
|
|
- collection.selection = 0
|
|
|
|
|
- }
|
|
|
|
|
- m.widget = collection
|
|
|
|
|
- return m, collection.view
|
|
|
|
|
- }
|
|
|
|
|
- return m, nil
|
|
|
|
|
- case "k":
|
|
|
|
|
- // do something only if widget is collection
|
|
|
|
|
- if collection, ok := m.widget.(IssueCollection); ok {
|
|
|
|
|
- if collection.selection != 0 {
|
|
|
|
|
- collection.selection = collection.selection - 1
|
|
|
|
|
- } else {
|
|
|
|
|
- collection.selection = len(collection.Collection) - 1
|
|
|
|
|
- }
|
|
|
|
|
- m.widget = collection
|
|
|
|
|
- return m, collection.view
|
|
|
|
|
- }
|
|
|
|
|
- return m, nil
|
|
|
|
|
- case "enter":
|
|
|
|
|
- if _, ok := m.widget.(IssueCollection); ok {
|
|
|
|
|
- m.Path = m.widget.(IssueCollection).Collection[m.widget.(IssueCollection).selection].Path
|
|
|
|
|
- return m, m.load
|
|
|
|
|
- }
|
|
|
|
|
- return m, nil
|
|
|
|
|
}
|
|
}
|
|
|
case widget:
|
|
case widget:
|
|
|
switch T := msg.(type) {
|
|
switch T := msg.(type) {
|
|
|
- case Issue:
|
|
|
|
|
|
|
+ default:
|
|
|
m.widget = T
|
|
m.widget = T
|
|
|
return m, T.view
|
|
return m, T.view
|
|
|
- case IssueCollection:
|
|
|
|
|
|
|
+ case issueCreate:
|
|
|
|
|
+ T = T.init(Issue{Path: m.Path})
|
|
|
m.widget = T
|
|
m.widget = T
|
|
|
return m, T.view
|
|
return m, T.view
|
|
|
}
|
|
}
|