Unverified Commit bb403e22 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

More passes on next and read

parent a13e83a1
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -28,12 +28,16 @@ repl.commands?
## Things to do

  * Run [godoc](http://localhost:6060/) and then review where the help text is lacking.
  * Move to a storage layer.  Next: this.Folder should be a storage.Folder.
  * Implement batch jobs - and have install populate the database with some
    test data.
  * ~~Move to a storage layer.~~
  * this.Folder should be a storage.Folder.
  * Implement batch jobs
     * ~~Have install populate the database with some test data.~~
     * reboot
     * expire
  * Implement each command.
    * Next: folder commands - ~~CREATE~~, ~~REMOVE~~, MODIFY, ~~INDEX~~, ~~SELECT~~
    * Messages: ~~ADD~~, CURRENT, ~~DIRECTORY~~, BACK, CHANGE, FIRST, REMOVE, NEXT, ~~READ~~
    * Messages: ~~ADD~~, CURRENT, ~~DIRECTORY~~, BACK, CHANGE,
                FIRST, REMOVE, ~~NEXT~~, ~~READ~~
    * Messages edit: CHANGE, REPLY, FORWARD
    * Moving messages: COPY, MOVE
    * Compound commands: SET and SHOW - make HELP work for them.
+0 −2
Original line number Diff line number Diff line
@@ -39,10 +39,8 @@ func Editor(placeholder, title string) (string, error) {
	updateInfos := func() {
		fromRow, fromColumn, toRow, toColumn := textArea.GetCursor()
		if fromRow == toRow && fromColumn == toColumn {
			// position.SetText(fmt.Sprintf("Row: [yellow]%d[white], Column: [yellow]%d ", fromRow, fromColumn))
			position.SetText(fmt.Sprintf("Row: %d, Column: %d ", fromRow, fromColumn))
		} else {
			// position.SetText(fmt.Sprintf("[red]From[white] Row: [yellow]%d[white], Column: [yellow]%d[white] - [red]To[white] Row: [yellow]%d[white], To Column: [yellow]%d ", fromRow, fromColumn, toRow, toColumn))
			position.SetText(fmt.Sprintf("From Row: %d, Column: %d - To Row: %d, To Column: %d ", fromRow, fromColumn, toRow, toColumn))
		}
	}
+15 −0
Original line number Diff line number Diff line
@@ -62,6 +62,21 @@ func ReadMessage(login, folder string, msgid int64) (*storage.Message, error) {
	return &msg, nil
}

// NextMsgid gets the next message id.
func NextMsgid(login, folder string, msgid int64) int64 {
	ctx := context.TODO()
	newid, err := this.Q.NextMsgid(ctx, storage.NextMsgidParams{
		Folder:   folder,
		Folder_2: folder,
		Login:    login,
		ID:       msgid,
	})
	if err != nil {
		return 0
	}
	return newid
}

// ListMessages lists messages.
func ListMessages(folder string) ([]storage.Message, error) {
	ctx := context.TODO()
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ import (
	"github.com/adrg/xdg"
)

var keytemplate = `command="%s -u %s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s\n`
var keytemplate = `command="%s -u %s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s\n`

// Add adds an ssh key to the `authorized_keys` file.
func Add(login, public string) error {

pager/tview.go

0 → 100644
+59 −0
Original line number Diff line number Diff line
package pager

import (
	"github.com/gdamore/tcell/v2"
	"github.com/rivo/tview"
)

// Pager is the pager for text data.
func Pager(text string) error {
	theme := tview.Theme{
		PrimitiveBackgroundColor:    tcell.ColorDefault,
		ContrastBackgroundColor:     tcell.ColorDefault,
		MoreContrastBackgroundColor: tcell.ColorDefault,
		BorderColor:                 tcell.ColorDefault,
		TitleColor:                  tcell.ColorDefault,
		GraphicsColor:               tcell.ColorDefault,
		PrimaryTextColor:            tcell.ColorDefault,
		SecondaryTextColor:          tcell.ColorDefault,
		TertiaryTextColor:           tcell.ColorDefault,
		InverseTextColor:            tcell.ColorDefault,
		ContrastSecondaryTextColor:  tcell.ColorDefault,
	}
	tview.Styles = theme
	app := tview.NewApplication()

	page := tview.NewTextView().
		SetWrap(true).
		SetScrollable(true).
		SetChangedFunc(func() {
			app.Draw()
		}).
		SetText(text)
	// TODO: this doesn't seem to be working.
	page.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
		switch event.Key() {
		case tcell.KeyRune:
			switch event.Rune() {
			case 'B', 'b':
				_, y := page.GetScrollOffset()
				_, _, _, height := page.GetInnerRect()
				page.ScrollTo(0, max(y+height, 0))
				return nil
			case ' ':
				_, y := page.GetScrollOffset()
				_, _, _, height := page.GetInnerRect()
				page.ScrollTo(0, y+height)
				return nil
			case 'Q', 'q':
				app.Stop()
				return nil
			}
		case tcell.KeyEsc, tcell.KeyCtrlC:
			app.Stop()
			return nil
		}
		return event
	})
	return app.SetRoot(page, true).Run()
}
Loading