Skip to content
Snippets Groups Projects
Unverified Commit d850e500 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Some readline cleanup

parent 9a012a54
Branches
Tags
No related merge requests found
...@@ -16,11 +16,14 @@ Look up how godoc does references to other things. ...@@ -16,11 +16,14 @@ Look up how godoc does references to other things.
Look up how to run migrations on the db from embedded files. Look up how to run migrations on the db from embedded files.
Figure out readline completion. Case sensitive - issue? Building from
repl.commands?
## Things to do ## Things to do
* Implement a better dclish parser. * Implement a better dclish parser.
* Implement each command. * Implement each command.
* Next: HELP - move some commands to a Help array. * Next: ????
* Decide on how the boards are managed. * Decide on how the boards are managed.
## Module links ## Module links
......
...@@ -51,7 +51,7 @@ func Open(acc string) error { ...@@ -51,7 +51,7 @@ func Open(acc string) error {
if err != nil { if err != nil {
return errors.New("account preference directory problem") return errors.New("account preference directory problem")
} }
User.pref, err = sql.Open("sqlite", path.Join(prefdir, acc, ".db")) User.pref, err = sql.Open("sqlite", path.Join(prefdir, fmt.Sprintf("%s.%s", acc, ".db")))
if err != nil { if err != nil {
return errors.New("account preference database problem") return errors.New("account preference database problem")
} }
......
...@@ -23,10 +23,10 @@ type Flags map[string]*Flag ...@@ -23,10 +23,10 @@ type Flags map[string]*Flag
// Command contains the definition of a command, it's flags and subcommands. // Command contains the definition of a command, it's flags and subcommands.
type Command struct { type Command struct {
Flags Flags Flags Flags
// TODO: FlagOrder []string FlagOrder []string
Args []string Args []string
// TODO: MaxArgs int MaxArgs int
// TODO: MinArgs int MinArgs int
Commands []*Command Commands []*Command
Action ActionFunc Action ActionFunc
Description string Description string
......
...@@ -52,7 +52,7 @@ use is to create a folder for posting SYSTEM messages only meant for a ...@@ -52,7 +52,7 @@ use is to create a folder for posting SYSTEM messages only meant for a
certain UIC group. This is done by creating a PRIVATE SYSTEM folder, and certain UIC group. This is done by creating a PRIVATE SYSTEM folder, and
giving access to that UIC group. Only users in that UIC group will see giving access to that UIC group. Only users in that UIC group will see
the messages in that folder when they log in.`, the messages in that folder when they log in.`,
"Ctrl-C": `Except for when BULLETIN is awaiting input from the terminal, a "CTRL-C": `Except for when BULLETIN is awaiting input from the terminal, a
CTRL-C will cause BULLETIN to abort the execution of any command. If CTRL-C will cause BULLETIN to abort the execution of any command. If
BULLETIN is waiting for terminal input, a CTRL-C will cause BULLETIN BULLETIN is waiting for terminal input, a CTRL-C will cause BULLETIN
to return to the BULLETIN> prompt. If for some reason the user wishes to return to the BULLETIN> prompt. If for some reason the user wishes
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
package repl package repl
import ( import (
"fmt" "errors"
"os"
"git.lyda.ie/kevin/bulletin/accounts" "git.lyda.ie/kevin/bulletin/accounts"
"git.lyda.ie/kevin/bulletin/dclish" "git.lyda.ie/kevin/bulletin/dclish"
...@@ -12,17 +11,13 @@ import ( ...@@ -12,17 +11,13 @@ import (
// ActionQuit handles the `QUIT` command. // ActionQuit handles the `QUIT` command.
func ActionQuit(_ *dclish.Command) error { func ActionQuit(_ *dclish.Command) error {
accounts.User.Close() accounts.User.Close()
fmt.Println("QUIT") // TODO: IIRC, quit should not update unread data. Check old code to confirm.
// TODO: IIRC, quit should not update unread data. Check. return errors.New("QUIT")
os.Exit(0)
return nil
} }
// ActionExit handles the `EXIT` command. // ActionExit handles the `EXIT` command.
func ActionExit(_ *dclish.Command) error { func ActionExit(_ *dclish.Command) error {
accounts.User.Close() accounts.User.Close()
fmt.Println("EXIT")
// TODO: update unread data. // TODO: update unread data.
os.Exit(0) return errors.New("EXIT")
return nil
} }
...@@ -3,14 +3,24 @@ package repl ...@@ -3,14 +3,24 @@ package repl
import ( import (
"fmt" "fmt"
"path"
"github.com/adrg/xdg"
"github.com/chzyer/readline" "github.com/chzyer/readline"
) )
// Loop is the main event loop. // Loop is the main event loop.
func Loop(user string) error { func Loop(user string) error {
fmt.Printf("TODO: get config for user %s using xdg.", user) fmt.Printf("TODO: get config for user %s using xdg.\n", user)
rl, err := readline.New("BULLETIN> ") rl, err := readline.NewEx(
&readline.Config{
Prompt: "BULLETIN> ",
HistoryFile: path.Join(xdg.ConfigHome, "BULLETIN", fmt.Sprintf("%s.history", user)),
// TODO: AutoComplete: completer,
InterruptPrompt: "^C",
EOFPrompt: "EXIT",
HistorySearchFold: true,
})
if err != nil { if err != nil {
return err return err
} }
...@@ -19,6 +29,11 @@ func Loop(user string) error { ...@@ -19,6 +29,11 @@ func Loop(user string) error {
for { for {
line, err := rl.Readline() line, err := rl.Readline()
if err != nil { if err != nil {
if err.Error() == "Interrupt" {
commands.ParseAndRun("QUIT")
} else if err.Error() == "EOF" {
commands.ParseAndRun("EXIT")
}
return err return err
} }
if len(line) == 0 { if len(line) == 0 {
...@@ -29,6 +44,4 @@ func Loop(user string) error { ...@@ -29,6 +44,4 @@ func Loop(user string) error {
return err return err
} }
} }
return nil
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment