Skip to content

Commit

Permalink
improve: tidying code and description
Browse files Browse the repository at this point in the history
  • Loading branch information
egin10 committed Apr 11, 2024
1 parent ff54e71 commit 989486d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module gin-dapodik
go 1.22.2

require (
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/huh v0.3.0
github.com/charmbracelet/huh/spinner v0.0.0-20240404200615-66118a2cb3cf
github.com/charmbracelet/lipgloss v0.10.0
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be
github.com/gocolly/colly v1.2.0
github.com/xuri/excelize/v2 v2.8.1
Expand All @@ -21,7 +20,7 @@ require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/bubbles v0.18.0 // indirect
github.com/charmbracelet/bubbletea v0.25.0 // indirect
github.com/charmbracelet/lipgloss v0.10.0 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -39,7 +38,6 @@ require (
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
github.com/temoto/robotstxt v1.1.2 // indirect
github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
github.com/charmbracelet/huh v0.3.0 h1:CxPplWkgW2yUTDDG0Z4S5HH8SJOosWHd4LxCvi0XsKE=
github.com/charmbracelet/huh v0.3.0/go.mod h1:fujUdKX8tC45CCSaRQdw789O6uaCRwx8l2NDyKfC4jA=
github.com/charmbracelet/huh/spinner v0.0.0-20240404200615-66118a2cb3cf h1:vchktTn7AISETgCrui5AMo0TtGVbXk/mB3ZR4ENoTX8=
github.com/charmbracelet/huh/spinner v0.0.0-20240404200615-66118a2cb3cf/go.mod h1:nrBG0YEHaxdbqHXW1xvG1hPqkuac9Eg7RTMvogiXuz0=
github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s=
github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE=
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=
Expand Down Expand Up @@ -75,8 +73,6 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7AwssoOcM/tq5JjjG2yYOc8odClEiXA=
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
30 changes: 11 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import (
"strconv"
"strings"

"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
"github.com/common-nighthawk/go-figure"
)

Expand All @@ -26,8 +24,6 @@ type Model struct {

accessible bool
process string

spinner spinner.Model
}

type done int
Expand All @@ -36,30 +32,28 @@ func initialModel() Model {
accessible, _ := strconv.ParseBool(os.Getenv("ACCESSIBLE"))

myFigure := figure.NewFigure("GIN-DAPODIK", "", true)
welcomeMsg := "Selamat datang di Gin-Dapodik 👾.\n"
welcomeMsg += "Aplikasi ini hanya bisa digunakan untuk mengambil data sekolah \nsesuai dengan satuan pendidikan & provinsi yang diinginkan 👾"
welcomeMsg := "Aplikasi ini hanya bisa digunakan untuk mengambil data sekolah\n"
welcomeMsg += "sesuai dengan satuan pendidikan & provinsi yang diinginkan pada website\n"
welcomeMsg += "https://referensi.data.kemdikbud.go.id\n\n"
welcomeMsg += "Tekan ctrl+c untuk close program"

header := fmt.Sprintf(
"%s\n%s",
myFigure.String(),
welcomeMsg,
)

s := spinner.New()
s.Spinner = spinner.Monkey
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))

return Model{
menuIndex: 0,
optionValue: model.OptionValue{},
accessible: accessible,
process: "",
spinner: s,
header: header,
}
}

func (m Model) Init() tea.Cmd {
return m.spinner.Tick
return nil
}

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
Expand All @@ -72,10 +66,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case done:
m.menuIndex = 0
m.process = fmt.Sprintf(
"\nData selesai di download dengan format file (.%s) 🗿\nTekan Enter untuk kembali ke menu awal.",
m.optionValue.ExportTo,
)
m.process = fmt.Sprintf("Data selesai diunduh dengan format file (.%s) 🗿\n", m.optionValue.ExportTo)
m.process += "Tekan Enter untuk kembali ke menu awal.\n"
// m.process += "Tekan ctrl+c untuk menutup aplikasi.\n"
return m, nil
}

Expand All @@ -95,10 +88,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.menuIndex++

str := fmt.Sprintf(
"\n%s Sedang mengunduh data %s di %s...\nProses ini tergantung koneksi internet anda.\n",
m.spinner.View(),
"🗂️ Sedang mengunduh data %s di %s...\nProses ini tergantung koneksi internet anda.\n",
strings.ToUpper(m.optionValue.SatuanPendidikan.Path),
m.optionValue.Provinsi.Name,
strings.ToUpper(m.optionValue.Provinsi.Name),
)
m.process = str

Expand Down

0 comments on commit 989486d

Please sign in to comment.