ok, i think we've got the admin screen working now
Ted Unangst tedu@tedunangst.com
Sun, 20 Oct 2019 20:09:44 -0400
3 files changed,
64 insertions(+),
57 deletions(-)
M
admin.go
→
admin.go
@@ -16,7 +16,6 @@
package main import ( - "html/template" "io/ioutil" "log"@@ -27,6 +26,28 @@
func adminscreen() { log.SetOutput(ioutil.Discard) + messages := []*struct { + name string + label string + text string + }{ + { + name: "servermsg", + label: "server", + text: string(serverMsg), + }, + { + name: "aboutmsg", + label: "about", + text: string(aboutMsg), + }, + { + name: "loginmsg", + label: "login", + text: string(loginMsg), + }, + } + app := tview.NewApplication() var maindriver func(event *tcell.EventKey) *tcell.EventKey@@ -51,59 +72,31 @@ row := 0
{ col := 0 headcell := tview.TableCell{ - Color: tcell.ColorWhite, - } - cell := dupecell(&headcell) - cell.Text = "Message" - table.SetCell(row, col, cell) - col++ - cell = dupecell(&headcell) - cell.Text = "" - table.SetCell(row, col, cell) - - row++ - } - { - col := 0 - headcell := tview.TableCell{ - Color: tcell.ColorWhite, - } - cell := dupecell(&headcell) - cell.Text = "Server" - table.SetCell(row, col, cell) - col++ - cell = dupecell(&headcell) - cell.Text = tview.Escape(string(serverMsg)) - table.SetCell(row, col, cell) - - row++ - } - { - col := 0 - headcell := tview.TableCell{ - Color: tcell.ColorWhite, + Color: tcell.ColorWhite, + NotSelectable: true, } cell := dupecell(&headcell) - cell.Text = "About" + cell.Text = "which " table.SetCell(row, col, cell) col++ cell = dupecell(&headcell) - cell.Text = tview.Escape(string(aboutMsg)) + cell.Text = "message" table.SetCell(row, col, cell) row++ } - { + for i := 0; i < 3; i++ { col := 0 + msg := messages[i] headcell := tview.TableCell{ Color: tcell.ColorWhite, } cell := dupecell(&headcell) - cell.Text = "Login" + cell.Text = msg.label table.SetCell(row, col, cell) col++ cell = dupecell(&headcell) - cell.Text = tview.Escape(string(loginMsg)) + cell.Text = tview.Escape(msg.text) table.SetCell(row, col, cell) row++@@ -124,9 +117,7 @@ return event
} editform := tview.NewForm() - namebox := tview.NewInputField().SetLabel("name").SetFieldWidth(20) - descbox := tview.NewInputField().SetLabel("description").SetFieldWidth(60) - orderbox := tview.NewInputField().SetLabel("order").SetFieldWidth(10) + descbox := tview.NewInputField().SetLabel("msg: ").SetFieldWidth(60) editform.AddButton("save", nil) editform.AddButton("cancel", nil) savebutton := editform.GetButton(0)@@ -138,33 +129,40 @@ editform.SetButtonBackgroundColor(tcell.ColorBlack)
editform.GetButton(1).SetSelectedFunc(showtable) editform.SetCancelFunc(showtable) - hadchanges := false + editframe := tview.NewFrame(editform) + editframe.SetBorders(1, 0, 1, 0, 4, 0) showform := func() { editform.Clear(false) - editform.AddFormItem(namebox) editform.AddFormItem(descbox) - editform.AddFormItem(orderbox) app.SetInputCapture(arrowadapter) - app.SetRoot(editform, true) + app.SetRoot(editframe, true) } - editrepo := func(which string) { - namebox.SetText(which) - descbox.SetText("message") + editmsg := func(which int) { + msg := messages[which] + editframe.Clear() + editframe.AddText(tview.Escape("edit "+msg.label+" message"), + true, 0, tcell.ColorGreen) + descbox.SetText(msg.text) savebutton.SetSelectedFunc(func() { - serverMsg = template.HTML(descbox.GetText()) - hadchanges = true + msg.text = descbox.GetText() + updateconfig(msg.name, msg.text) showtable() }) showform() } + table.SetSelectedFunc(func(row, col int) { + editmsg(row - 1) + }) + maindriver = func(event *tcell.EventKey) *tcell.EventKey { switch event.Rune() { - case 'd': case 'e': - editrepo("servermsg") + r, _ := table.GetSelection() + r-- + editmsg(r) case 'q': app.Stop() return nil
M
docs/changelog.txt
→
docs/changelog.txt
@@ -2,6 +2,8 @@ changelog
-- next ++ Somewhat functional admin console (TTY). + + More JS free fallbacks for some basic functions. + Add chpass command.
M
docs/honk.8
→
docs/honk.8
@@ -81,13 +81,20 @@ Site CSS may be overridden by creating a
.Pa views/local.css file. .Pp -Custom messages may be set by editing the database. -(Sorry.) -.Dl update config set value = 'message' where key = 'servermsg'; -.Dl update config set value = 'message' where key = 'aboutmsg'; -.Dl update config set value = 'message' where key = 'loginmsg'; +Custom HTML messages may be added to select pages by using the +.Ic admin +command. +.Dl ./honk admin +.Bl -tag -width tenletters +.It server +Displayed on the home page. +.It about +Displayed on the about page. +.It login +Displayed about the login form. +.El .Pp -.Ss ADMIN +.Ss USER ADMIN New users can be added with the .Ic adduser command.