Skip to content

Commit

Permalink
update The external hard drive will be deleted directly (a confirmati…
Browse files Browse the repository at this point in the history
…on message will be displayed)
  • Loading branch information
yorukot committed Apr 8, 2024
1 parent 52ede94 commit a4232a8
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 74 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ All notable changes to this project will be documented in this file. Dates are d
- The user can enter the path, which will be the path of the first file panel [`14620b3`](https://github.com/MHNightCat/superfile/commit/14620b33b09edfce80a95e1f52f7f66b3686a9d0)
- Make user can open file with default browser text-editor etc [`f47d291`](https://github.com/MHNightCat/superfile/commit/f47d2915bf637da0cf99a4b15fa0bea8edc8d380)
- Can open terminal in focused file panel path [`f47d291`](https://github.com/MHNightCat/superfile/commit/f47d2915bf637da0cf99a4b15fa0bea8edc8d380)

- The external hard drive will be deleted directly (a confirmation message will be displayed) [``]()
#### Bug fix

- Fix processes bar cursor index display error [`f6eb9d8`](https://github.com/MHNightCat/superfile/commit/f6eb9d879f9f7ef31859e3f84c8792e2f0fc543a)
Expand Down
18 changes: 18 additions & 0 deletions release/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

projectName="superfile"
version="v1.0.1"
osList=("darwin" "freebsd" "linux" "openbsd" "netbsd")
archList=("amd64" "arm" "arm64")
mkdir dist

for os in "${osList[@]}"; do
for arch in "${archList[@]}"; do
echo $projectName-$os-$version-$arch
mkdir ./dist/$projectName-$os-$version-$arch
cd ../src
go build -o ../release/dist/$projectName-$os-$version-$arch/spf main.go
cd ../release
tar czf ./dist/$projectName-$os-$version-$arch.tar.gz ./dist/$projectName-$os-$version-$arch
done
done
22 changes: 11 additions & 11 deletions src/components/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package components
import (
"encoding/json"
"fmt"
"github.com/rkoesters/xdg/userdirs"
"io"
"log"
"math"
Expand All @@ -13,8 +14,6 @@ import (
"sort"
"strconv"
"strings"

"github.com/rkoesters/xdg/userdirs"
)

func getFolder() []folder {
Expand Down Expand Up @@ -43,10 +42,7 @@ func getFolder() []folder {
OutPutLog("Read superfile data error", err)
}
var pinnedFolder []string
err = json.Unmarshal(jsonData, &pinnedFolder)
if err != nil {
OutPutLog("Unmarshal superfile data error", err)
}
json.Unmarshal(jsonData, &pinnedFolder)
folders := []folder{
{location: HomeDir, name: "󰋜 Home"},
{location: userdirs.Download, name: "󰏔 Downloads"},
Expand Down Expand Up @@ -296,8 +292,8 @@ func PasteDir(src, dst string, id string, m model) (model, error) {
p.name = "󰆏 " + filepath.Base(path)
}

if len(processBarChannel) < 5 {
processBarChannel <- processBarMessage{
if len(channel) < 5 {
channel <- channelMessage{
processId: id,
processNewState: p,
}
Expand All @@ -306,15 +302,15 @@ func PasteDir(src, dst string, id string, m model) (model, error) {
err := PasteFile(path, newPath)
if err != nil {
p.state = failure
processBarChannel <- processBarMessage{
channel <- channelMessage{
processId: id,
processNewState: p,
}
return err
}
p.done++
if len(processBarChannel) < 5 {
processBarChannel <- processBarMessage{
if len(channel) < 5 {
channel <- channelMessage{
processId: id,
processNewState: p,
}
Expand Down Expand Up @@ -431,3 +427,7 @@ func countFiles(dirPath string) (int, error) {

return count, err
}

func IsExternalPath(path string) bool {
return strings.HasPrefix(path, "/run/media")
}
31 changes: 16 additions & 15 deletions src/components/globalController.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package components

import (
"encoding/json"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/textinput"
"github.com/lithammer/shortuuid"
"github.com/rkoesters/xdg/trash"
"log"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"time"

"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/textinput"
"github.com/lithammer/shortuuid"
"github.com/rkoesters/xdg/trash"
)

/* CURSOR CONTROLLER START */
Expand Down Expand Up @@ -297,7 +298,7 @@ func PasteItem(m model) model {

m.processBarModel.process[id] = newProcess

processBarChannel <- processBarMessage{
channel <- channelMessage{
processId: id,
processNewState: newProcess,
}
Expand All @@ -315,7 +316,7 @@ func PasteItem(m model) model {
p = m.processBarModel.process[id]
if err != nil {
p.state = failure
processBarChannel <- processBarMessage{
channel <- channelMessage{
processId: id,
processNewState: p,
}
Expand All @@ -327,7 +328,7 @@ func PasteItem(m model) model {
p.state = successful
p.done = totalFiles
p.doneTime = time.Now()
processBarChannel <- processBarMessage{
channel <- channelMessage{
processId: id,
processNewState: p,
}
Expand Down Expand Up @@ -360,10 +361,10 @@ func PanelCreateNewFile(m model) model {
ti.CharLimit = 156
ti.Width = modalWidth - 10

m.createNewItem.location = panel.location
m.createNewItem.itemType = newFile
m.createNewItem.open = true
m.createNewItem.textInput = ti
m.typingModal.location = panel.location
m.typingModal.itemType = newFile
m.typingModal.open = true
m.typingModal.textInput = ti
m.firstTextInput = true

m.fileModel.filePanels[m.filePanelFocusIndex] = panel
Expand All @@ -379,10 +380,10 @@ func PanelCreateNewFolder(m model) model {
ti.CharLimit = 156
ti.Width = modalWidth - 10

m.createNewItem.location = panel.location
m.createNewItem.itemType = newFolder
m.createNewItem.open = true
m.createNewItem.textInput = ti
m.typingModal.location = panel.location
m.typingModal.itemType = newFolder
m.typingModal.open = true
m.typingModal.textInput = ti
m.firstTextInput = true

m.fileModel.filePanels[m.filePanelFocusIndex] = panel
Expand Down
54 changes: 40 additions & 14 deletions src/components/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var Config ConfigType
var logOutput *os.File
var et *exiftool.Exiftool

var processBarChannel = make(chan processBarMessage, 1000)
var channel = make(chan channelMessage, 1000)

func InitialModel(dir string) model {
var err error
Expand Down Expand Up @@ -105,7 +105,7 @@ func InitialModel(dir string) model {
}
}

func listenForProcessBarMessage(msg chan processBarMessage) tea.Cmd {
func listenForchannelMessage(msg chan channelMessage) tea.Cmd {
return func() tea.Msg {
select {
case m := <-msg:
Expand All @@ -120,18 +120,22 @@ func (m model) Init() tea.Cmd {
return tea.Batch(
tea.SetWindowTitle("SuperFile"),
textinput.Blink, // Assuming textinput.Blink is a valid command
listenForProcessBarMessage(processBarChannel),
listenForchannelMessage(channel),
)
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch msg := msg.(type) {
case processBarMessage:
if !contains(m.processBarModel.processList, msg.processId) {
m.processBarModel.processList = append(m.processBarModel.processList, msg.processId)
case channelMessage:
if msg.returnWarnModal {
m.warnModal = msg.warnModal
} else {
if !contains(m.processBarModel.processList, msg.processId) {
m.processBarModel.processList = append(m.processBarModel.processList, msg.processId)
}
m.processBarModel.process[msg.processId] = msg.processNewState
}
m.processBarModel.process[msg.processId] = msg.processNewState
case tea.WindowSizeMsg:
m.mainPanelHeight = msg.Height - bottomBarHeight
m.fileModel.width = (msg.Width - sideBarWidth - (4 + (len(m.fileModel.filePanels)-1)*2)) / len(m.fileModel.filePanels)
Expand All @@ -140,14 +144,32 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
case tea.KeyMsg:
// if in the create item modal
if m.createNewItem.open {
if m.typingModal.open {
switch msg.String() {
case Config.Cancel[0], Config.Cancel[1]:
m = CancelModal(m)
m = CancelTypingModal(m)
case Config.Confirm[0], Config.Confirm[1]:
m = CreateItem(m)
}
// if in the renaming mode
} else if m.warnModal.open {
switch msg.String() {
case Config.Cancel[0], Config.Cancel[1]:
m = CancelWarnModal(m)
case Config.Confirm[0], Config.Confirm[1]:
m.warnModal.open = false
if m.fileModel.filePanels[m.filePanelFocusIndex].panelMode == selectMode {
go func() {
m = CompletelyDeleteMultipleFile(m)
m.fileModel.filePanels[m.filePanelFocusIndex].selected = m.fileModel.filePanels[m.filePanelFocusIndex].selected[:0]
}()
} else {
go func() {
m = CompletelyDeleteSingleFile(m)
}()
}
}
// if in the renaming mode
} else if m.fileModel.renaming {
switch msg.String() {
case Config.Cancel[0], Config.Cancel[1]:
Expand Down Expand Up @@ -237,7 +259,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case Config.FilePanelSelectModeItemDelete[0], Config.FilePanelSelectModeItemDelete[1]:
go func() {
m = DeleteMultipleItem(m)
m.fileModel.filePanels[m.filePanelFocusIndex].selected = m.fileModel.filePanels[m.filePanelFocusIndex].selected[:0]
if !IsExternalPath(m.fileModel.filePanels[m.filePanelFocusIndex].location) {
m.fileModel.filePanels[m.filePanelFocusIndex].selected = m.fileModel.filePanels[m.filePanelFocusIndex].selected[:0]
}
}()
case Config.FilePanelSelectModeItemCopy[0], Config.FilePanelSelectModeItemCopy[1]:
m = CopyMultipleItem(m)
Expand Down Expand Up @@ -280,14 +304,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} else if m.fileModel.renaming {
m.fileModel.filePanels[m.filePanelFocusIndex].rename, cmd = m.fileModel.filePanels[m.filePanelFocusIndex].rename.Update(msg)
} else {
m.createNewItem.textInput, cmd = m.createNewItem.textInput.Update(msg)
m.typingModal.textInput, cmd = m.typingModal.textInput.Update(msg)
}

if m.fileModel.filePanels[m.filePanelFocusIndex].cursor < 0 {
m.fileModel.filePanels[m.filePanelFocusIndex].cursor = 0
}

cmd = tea.Batch(cmd, listenForProcessBarMessage(processBarChannel))
cmd = tea.Batch(cmd, listenForchannelMessage(channel))
m.sideBarModel.pinnedModel.folder = getFolder()
return m, cmd
}
Expand All @@ -296,8 +320,10 @@ func (m model) View() string {
// check is the terminal size enough
if m.fullHeight < minimumHeight || m.fullWidth < minimumWidth {
return TerminalSizeWarnRender(m)
} else if m.createNewItem.open {
return ModalRender(m)
} else if m.typingModal.open {
return TypineModalRender(m)
} else if m.warnModal.open {
return WarnModalRender(m)
} else {
sideBar := SideBarRender(m)

Expand Down
21 changes: 15 additions & 6 deletions src/components/modelRender.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,27 @@ func TerminalSizeWarnRender(m model) string {
" Height = " + terminalMinimumSize.Render(minimumHeightString))
}

func ModalRender(m model) string {
if m.createNewItem.itemType == newFile {
fileLocation := filePanelTopFolderIcon.Render("  ") + filePanelTopPath.Render(TruncateTextBeginning(m.createNewItem.location+"/"+m.createNewItem.textInput.Value(), modalWidth-4)) + "\n"
func TypineModalRender(m model) string {
if m.typingModal.itemType == newFile {
fileLocation := filePanelTopFolderIcon.Render("  ") + filePanelTopPath.Render(TruncateTextBeginning(m.typingModal.location+"/"+m.typingModal.textInput.Value(), modalWidth-4)) + "\n"
confirm := modalConfirm.Render(" (" + Config.Confirm[0] + ") New File ")
cancel := modalCancel.Render(" (" + Config.Cancel[0] + ") Cancel ")
tip := confirm + " " + cancel
return FullScreenStyle(m.fullHeight, m.fullWidth).Render(FocusedModalStyle(modalHeight, modalWidth).Render(fileLocation + "\n" + m.createNewItem.textInput.View() + "\n\n" + tip))
return FullScreenStyle(m.fullHeight, m.fullWidth).Render(FocusedModalStyle(modalHeight, modalWidth).Render(fileLocation + "\n" + m.typingModal.textInput.View() + "\n\n" + tip))
} else {
fileLocation := filePanelTopFolderIcon.Render("  ") + filePanelTopPath.Render(TruncateTextBeginning(m.createNewItem.location+"/"+m.createNewItem.textInput.Value(), modalWidth-4)) + "\n"
fileLocation := filePanelTopFolderIcon.Render("  ") + filePanelTopPath.Render(TruncateTextBeginning(m.typingModal.location+"/"+m.typingModal.textInput.Value(), modalWidth-4)) + "\n"
confirm := modalConfirm.Render(" (" + Config.Confirm[0] + ") New Folder ")
cancel := modalCancel.Render(" (" + Config.Cancel[0] + ") Cancel ")
tip := confirm + " " + cancel
return FullScreenStyle(m.fullHeight, m.fullWidth).Render(FocusedModalStyle(modalHeight, modalWidth).Render(fileLocation + "\n" + m.createNewItem.textInput.View() + "\n\n" + tip))
return FullScreenStyle(m.fullHeight, m.fullWidth).Render(FocusedModalStyle(modalHeight, modalWidth).Render(fileLocation + "\n" + m.typingModal.textInput.View() + "\n\n" + tip))
}
}

func WarnModalRender(m model) string {
title := m.warnModal.title
content := m.warnModal.content
confirm := modalCancel.Render(" (" + Config.Confirm[0] + ") Cofnirm ")
cancel := modalCancel.Render(" (" + Config.Cancel[0] + ") Cancel ")
tip := confirm + " " + cancel
return FullScreenStyle(m.fullHeight, m.fullWidth).Render(FocusedModalStyle(modalHeight, modalWidth).Render(title + "\n\n" + content + "\n\n" + tip))
}
Loading

0 comments on commit a4232a8

Please sign in to comment.