123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /**
- * 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"
- }
|