-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #467 from noborus/input-section-num
Added input mode for section header number
- Loading branch information
Showing
10 changed files
with
115 additions
and
24 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
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,61 @@ | ||
package oviewer | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/gdamore/tcell/v2" | ||
) | ||
|
||
// setSectionNumMode sets the inputMode to SectionNum. | ||
func (root *Root) setSectionNumMode() { | ||
input := root.input | ||
input.value = "" | ||
input.cursorX = 0 | ||
input.Event = newSectionNumEvent() | ||
} | ||
|
||
// eventSectionNum represents the section num input mode. | ||
type eventSectionNum struct { | ||
tcell.EventTime | ||
value string | ||
} | ||
|
||
// newSectionNumEvent returns Event. | ||
func newSectionNumEvent() *eventSectionNum { | ||
return &eventSectionNum{} | ||
} | ||
|
||
// Mode returns InputMode. | ||
func (e *eventSectionNum) Mode() InputMode { | ||
return SectionNum | ||
} | ||
|
||
// Prompt returns the prompt string in the input field. | ||
func (e *eventSectionNum) Prompt() string { | ||
return "Section Num:" | ||
} | ||
|
||
// Confirm returns the event when the input is confirmed. | ||
func (e *eventSectionNum) Confirm(str string) tcell.Event { | ||
e.value = str | ||
e.SetEventNow() | ||
return e | ||
} | ||
|
||
// Up returns strings when the up key is pressed during input. | ||
func (e *eventSectionNum) Up(str string) string { | ||
n, err := strconv.Atoi(str) | ||
if err != nil { | ||
return "0" | ||
} | ||
return strconv.Itoa(n + 1) | ||
} | ||
|
||
// Down returns strings when the down key is pressed during input. | ||
func (e *eventSectionNum) Down(str string) string { | ||
n, err := strconv.Atoi(str) | ||
if err != nil || n <= 0 { | ||
return "0" | ||
} | ||
return strconv.Itoa(n - 1) | ||
} |
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