inital working commit

This commit is contained in:
2024-04-20 10:33:41 -04:00
commit 1afe0716f5
17 changed files with 1179 additions and 0 deletions

91
printer/log.go Normal file
View File

@@ -0,0 +1,91 @@
package printer
import (
"fmt"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"time"
)
func (p *Printer) LogSuccess(message string) {
fmt.Println(p.getSuccess().Render("✅ " + message))
}
func (p *Printer) LogInfo(message string) {
fmt.Println(p.getInfo().Render(" " + message))
}
func (p *Printer) LogError(message string) {
fmt.Println(p.getError().Render("❌ " + message))
}
type model struct {
spinner spinner.Model
quitting bool
err error
message string
}
func (*Printer) LogSpinner(message string, done chan bool) {
p := tea.NewProgram(initialModel(message))
go p.Run()
for {
select {
case <-done:
p.Kill()
}
time.Sleep(100 * time.Millisecond)
}
}
func initialModel(message string) model {
s := spinner.New()
s.Spinner = spinner.MiniDot
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")).PaddingTop(1).PaddingLeft(2)
return model{spinner: s, message: message}
}
func (m model) Init() tea.Cmd {
return m.spinner.Tick
}
type errMsg error
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c":
m.quitting = true
return m, tea.Quit
default:
return m, nil
}
case errMsg:
m.err = msg
return m, nil
default:
var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg)
return m, cmd
}
}
func (m model) View() string {
if m.err != nil {
return m.err.Error()
}
str := fmt.Sprintf(" %s %s\n\n", m.spinner.View(), m.message)
if m.quitting {
return str + "\n"
}
return str
}

19
printer/printer.go Normal file
View File

@@ -0,0 +1,19 @@
package printer
import (
"fmt"
)
var Version = "0.0.0"
type Printer struct {
}
func NewPrinter() *Printer {
return &Printer{}
}
func (p *Printer) PrintTitle() {
fmt.Println(p.getBright().Render(fmt.Sprintf("RSA File Encryption Tool %s", Version)))
fmt.Println()
}

42
printer/styles.go Normal file
View File

@@ -0,0 +1,42 @@
package printer
import (
"github.com/charmbracelet/lipgloss"
)
func (*Printer) getBright() lipgloss.Style {
return lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#EDEEEDFF")).
Background(lipgloss.Color("#424E46FF")).
MarginTop(1).
PaddingLeft(3).
PaddingRight(3)
}
func (*Printer) getSuccess() lipgloss.Style {
return lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#00FF00")).
MarginTop(1).
MarginBottom(2).
PaddingLeft(2).
Width(120)
}
func (*Printer) getError() lipgloss.Style {
return lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#FF0000")).
PaddingLeft(2).
MarginTop(1).
MarginBottom(2).
Width(120)
}
func (*Printer) getInfo() lipgloss.Style {
return lipgloss.NewStyle().
Foreground(lipgloss.Color("#4E82B7FF")).
PaddingLeft(2).
Width(120)
}