Skip to content

Commit

Permalink
add AltKefunc in constants` pkg, add send and receive ui handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Feb 4, 2022
1 parent adc56d7 commit aaacf8e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
9 changes: 9 additions & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,12 @@ func CtrlKey() string {
return "ctrl"
}
}

func AltKey() string {
// if os is macos, then return "⌥"
if runtime.GOOS == "darwin" {
return "⌥"
} else {
return "alt"
}
}
85 changes: 85 additions & 0 deletions internal/tui/sr-ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package tui

import (
"fmt"
"sort"
"time"
"strings"

"github.com/abdfnx/tran/constants"
"github.com/charmbracelet/bubbles/spinner"
)

type UIUpdate struct {
Progress float32
}

type FileInfoMsg struct {
FileNames []string
Bytes int64
}

type ErrorMsg struct {
Message string
}

type ProgressMsg struct {
Progress float32
}

type FinishedMsg struct {
Files []string
PayloadSize int64
}

var WaitingSpinner = spinner.Dot

var CompressingSpinner = spinner.Globe

var TransferSpinner = spinner.Spinner{
Frames: []string{"» ", "»» ", "»»»", " "},
FPS: time.Millisecond * 400,
}

var ReceivingSpinner = spinner.Spinner{
Frames: []string{" ", " «", " ««", "«««"},
FPS: time.Second / 2,
}

func TopLevelFilesText(fileNames []string) string {
// parse top level file names and attach number of subfiles in them
topLevelFileChildren := make(map[string]int)

for _, f := range fileNames {
fileTopPath := strings.Split(f, "/")[0]

subfileCount, wasPresent := topLevelFileChildren[fileTopPath]

if wasPresent {
topLevelFileChildren[fileTopPath] = subfileCount + 1
} else {
topLevelFileChildren[fileTopPath] = 0
}
}

// read map into formatted strings
var topLevelFilesText []string

for fileName, subFileCount := range topLevelFileChildren {
formattedFileName := fileName

if subFileCount > 0 {
formattedFileName = fmt.Sprintf("%s (%d subfiles)", fileName, subFileCount)
}

topLevelFilesText = append(topLevelFilesText, formattedFileName)
}

sort.Strings(topLevelFilesText)

return strings.Join(topLevelFilesText, ", ")
}

func GracefulUIQuit() {
time.Sleep(constants.SHUTDOWN_PERIOD)
}

0 comments on commit aaacf8e

Please sign in to comment.