--- /dev/null
+all:
+ @echo "Options are: build and buildall"
+
+build:
+ @echo "Building for local os/arch..."
+ go build -o scientia-tui-`go env GOOS`-`go env GOARCH`
+
+buildall:
+ @echo "Building for linux/amd64 arch..."
+ GOOS=linux GOARCH=amd64 go build -o scientia-tui-linux-amd64
+ @echo "Done: scientia-tui-linux-amd64"
+ @echo "Building for windows/amd64 arch..."
+ GOOS=windows GOARCH=amd64 go build -o scientia-tui-windows-amd64
+ @echo "Done: scientia-tui-windows-amd64"
+ @echo "Building for macOS/amd64 arch..."
+ GOOS=darwin GOARCH=amd64 go build -o scientia-tui-darwin-amd64
+ @echo "Done: scientia-tui-darwin-amd64"
\ No newline at end of file
This is a very simple, with limited experience written, go program.
Use at own risk and feel free to improve.
-Howto build:
-Nothing special, just go build -o scientia-tui
+# Howto build:
+Nothing special, just use the provide Makefile or directly "go build -o scientia-tui" to use your current os/arch settings.
-Uses:
+# Uses:
https://github.com/charmbracelet/bubbletea
https://github.com/charmbracelet/bubbles
https://github.com/charmbracelet/lipgloss
+
+# Usage
+At first usage you need to create the config and the individual secret.
+Run $scientia-tui -create-config-file to create the default config file.
+The path to the config file is printed.
+Change the host address and update your server it with the secret, which is randomly created.
+
+Read from a file
+$ scientia-tui file.txt
+or piped
+$ cat file.txt | scientia-tui
+
+Commandline arguments (optional):
+ -create-config-file
+ Create default config file
+ -debug
+ Print debug infos
+ -verbose
+ Produce verbose output
+
ta := textarea.New()
ta.Placeholder = "Once upon a time..."
ta.SetHeight(10)
- ta.SetWidth(50)
+ ta.SetWidth(80)
ta.Focus()
return ta
func createView(m mainModel) string {
return lipgloss.JoinVertical(lipgloss.Left,
- headline.Render("Create a new entry"), m.create.View(),
+ headline.Render("Create a new entry"),
+ m.create.View(),
infoText.Render("esc*2 to get back and discard. ctrl+s to save."))
}
switch msg := msg.(type) {
- case tea.KeyMsg:
- switch msg.Type {
- case tea.KeyCtrlC:
- m.quitting = true
- return m, tea.Quit
- case tea.KeyCtrlS:
- m.choice = ""
- return m, nil
+ case tea.WindowSizeMsg:
+ m.create.SetWidth(msg.Width)
+ return m, nil
- case tea.KeyEsc:
- if m.create.Focused() {
- m.create.Blur()
- } else if !m.create.Focused() {
- m.choice = ""
- return m, nil
- }
- default:
- if !m.create.Focused() {
- cmd = m.create.Focus()
- cmds = append(cmds, cmd)
- }
- }
+ case tea.KeyMsg:
+ switch msg.Type {
+ case tea.KeyCtrlC:
+ m.quitting = true
+ return m, tea.Quit
+ case tea.KeyCtrlS:
+ m.choice = ""
+ return m, nil
+
+ case tea.KeyEsc:
+ if m.create.Focused() {
+ m.create.Blur()
+ } else if !m.create.Focused() {
+ m.choice = ""
+ return m, nil
+ }
+ default:
+ if !m.create.Focused() {
+ cmd = m.create.Focus()
+ cmds = append(cmds, cmd)
+ }
+ }
}
m.create, cmd = m.create.Update(msg)
--- /dev/null
+/**
+ * scientia
+ *
+ * A terminal client written in go.
+ *
+ * Copyright 2023 Johannes Keßler
+ *
+ * https://www.bananas-playground.net/projekt/scientia/
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program. If not, see http://www.sun.com/cddl/cddl.html
+ *
+ *
+ * This is the create "screen". It displays a textarea to input text into.
+ * Does the save and creation
+ */
+package main
+
+import (
+ "github.com/charmbracelet/bubbles/table"
+ tea "github.com/charmbracelet/bubbletea"
+ "github.com/charmbracelet/lipgloss"
+)
+
+var (
+ baseStyle = lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).BorderForeground(lipgloss.Color("240"))
+ headerStyle = lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).BorderForeground(lipgloss.Color("240")).BorderBottom(true).Bold(false)
+ selectedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("229")).Background(lipgloss.Color("57")).Bold(false)
+)
+
+func initList() table.Model {
+
+ columns := []table.Column{
+ {Title: "ID", Width: 4},
+ {Title: "Date", Width: 10},
+ {Title: "Body", Width: 10},
+ }
+
+ rows := []table.Row{
+ {"B0ug", "2023-02-17", "Determine this makefile"},
+ {"k291", "2023-02-16", "This is a terminal cli client written in g"},
+ {"A93a", "2023-02-15", "ava fallstricke https://www.fs-fmc.kit.edu/sites/default/fil"},
+ }
+
+ t := table.New(
+ table.WithColumns(columns),
+ table.WithRows(rows),
+ table.WithFocused(true),
+ table.WithHeight(10),
+ table.WithWidth(700),
+ )
+
+ s := table.DefaultStyles()
+ s.Header = headerStyle
+ s.Selected = selectedStyle
+ t.SetStyles(s)
+
+ return t
+}
+
+func listUpdate(msg tea.Msg, m mainModel) (tea.Model, tea.Cmd) {
+
+ var cmds []tea.Cmd
+ var cmd tea.Cmd
+
+ switch msg := msg.(type) {
+
+ case tea.WindowSizeMsg:
+ m.list.SetWidth(msg.Width)
+ return m, nil
+
+ case tea.KeyMsg:
+ switch msg.Type {
+ case tea.KeyCtrlC:
+ m.quitting = true
+ return m, tea.Quit
+ case tea.KeyEsc:
+ if m.list.Focused() {
+ m.list.Blur()
+ }
+ }
+ }
+
+ m.list, cmd = m.list.Update(msg)
+ cmds = append(cmds, cmd)
+ return m, tea.Batch(cmds...)
+}
+
+func listView(m mainModel) string {
+ return baseStyle.Render(m.list.View()) + "\n"
+}
import (
"fmt"
+ "github.com/charmbracelet/bubbles/table"
"github.com/charmbracelet/bubbles/textarea"
+ "github.com/charmbracelet/bubbles/viewport"
"github.com/charmbracelet/lipgloss"
"os"
// the unique identifiers for each action of the initial list of actions
const (
ITEM_CREATE_VALUE = "create"
- ITEM_LIST_VALUE = "list"
+ ITEM_LIST_VALUE = "list"
ITEM_UPDATE_VALUE = "update"
)
// mainModel Holds all the important stuff
// Needs to be extended if a new action is added
type mainModel struct {
- start list.Model
- create textarea.Model
- choice string
+ start list.Model
+ create textarea.Model
+ list table.Model
+ choice string
quitting bool
+ viewport viewport.Model
}
func (m mainModel) Init() tea.Cmd {
// Update The main Update method. Decides the correct action update method
func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch m.choice {
- case ITEM_UPDATE_VALUE:
- //return quitTextStyle.Render("Update it is")
- case ITEM_LIST_VALUE:
- //return quitTextStyle.Render("List it is")
- case ITEM_CREATE_VALUE:
- return createUpdate(msg, m)
+ case ITEM_UPDATE_VALUE:
+ //return quitTextStyle.Render("Update it is")
+ case ITEM_LIST_VALUE:
+ return listUpdate(msg, m)
+ case ITEM_CREATE_VALUE:
+ return createUpdate(msg, m)
}
return startUpdate(msg, m)
}
}
switch m.choice {
- case ITEM_UPDATE_VALUE:
- return quitTextStyle.Render("Update it is")
- case ITEM_LIST_VALUE:
- return quitTextStyle.Render("List it is")
- case ITEM_CREATE_VALUE:
- return createView(m)
+ case ITEM_UPDATE_VALUE:
+ return quitTextStyle.Render("Update it is")
+ case ITEM_LIST_VALUE:
+ return listView(m)
+ case ITEM_CREATE_VALUE:
+ return createView(m)
}
return startView(m)
}
func main() {
- m := mainModel{start: initStart(), create: initCreate()}
- p := tea.NewProgram(m)
+ m := mainModel{start: initStart(), create: initCreate(), list: initList()}
+ p := tea.NewProgram(m, tea.WithAltScreen())
- if err := p.Start(); err != nil {
+ if _, err := p.Run(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
}
helpStyle = list.DefaultStyles().HelpStyle.PaddingLeft(4).PaddingBottom(1)
)
-
// item stuff
type item struct {
title, desc string
}
+
func (i item) Title() string { return i.title }
func (i item) Description() string { return i.desc }
func (i item) FilterValue() string { return i.title }
}
func initStart() list.Model {
- items := []list.Item {
+ items := []list.Item{
item{title: "Create", desc: ITEM_CREATE_VALUE},
item{title: "List", desc: ITEM_LIST_VALUE},
item{title: "Update", desc: ITEM_UPDATE_VALUE},
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.start.SetWidth(msg.Width)
+ //m.viewport.Width = msg.Width
+ //m.viewport.Height = msg.Height
return m, nil
case tea.KeyMsg:
switch msg.Type {
- // esc does close?
- case tea.KeyEsc:
- return m, nil
- case tea.KeyCtrlC:
+ // esc does close?
+ case tea.KeyEsc:
+ return m, nil
+ case tea.KeyCtrlC:
+ m.quitting = true
+ return m, tea.Quit
+
+ case tea.KeyEnter:
+ i, ok := m.start.SelectedItem().(item)
+ if ok {
+ m.choice = i.Description()
+ }
+ return m, nil
+
+ case tea.KeyRunes:
+ switch string(msg.Runes) {
+ case "q":
m.quitting = true
return m, tea.Quit
-
- case tea.KeyEnter:
- i, ok := m.start.SelectedItem().(item)
- if ok {
- m.choice = i.Description()
- }
- return m, nil
-
- case tea.KeyRunes:
- switch string(msg.Runes) {
- case "q":
- m.quitting = true
- return m, tea.Quit
- }
}
+ }
}
var cmd tea.Cmd