cli

package
v0.0.0-...-a99c618 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandGoto     Command = "goto"
	CommandGotoPrev         = "goto prev"
	CommandGotoNext         = "goto next"
	CommandGotoRoot         = "goto /"

	CommandCursorMoveHome         = "cursor_move_home"
	CommandCursorMoveEnd          = "cursor_move_end"
	CommandCursorMoveUp           = "cursor_move_up"
	CommandCursorMovePageUp       = "cursor_move_page_up"
	CommandCursorMoveHalfPageUp   = "cursor_move_half_page_up"
	CommandCursorMoveDown         = "cursor_move_down"
	CommandCursorMovePageDown     = "cursor_move_page_down"
	CommandCursorMoveHalfPageDown = "cursor_move_half_page_down"
	CommandCursorMoveLeft         = "cursor_move_left"
	CommandCursorMoveRight        = "cursor_move_right"

	CommandCopyDirpath  = "copy_dirpath"
	CommandCopyFilename = "copy_filename"
	CommandCopyFilepath = "copy_filepath"
	CommandCopyFile     = "copy_file"

	CommandCutFile = "cut_file"

	CommandPasteFile = "paste_file"

	CommandDownloadFile = "download_file"

	CommandSyncExec = "sync_exec"

	// 模式切换
	CommandKeymap = "keymap"
	CommandHelp   = "help"
	CommandSync   = "sync"

	// 功能命令
	CommandFilter    = "filter" // 过滤
	CommandSystem    = "system"
	CommandInput     = "input" // 输入
	CommandBackspace = "backspace"
	CommandEnter     = "enter"
	CommandEnsure    = "ensure" // 确认
	CommandReload    = "reload"
	CommandDelete    = "delete"

	CommandQuit = "quit"
)
View Source
const (
	ModeNormal  Mode = "normal"
	ModeConfirm      = "confirm"
	ModeKeymap       = "keymap"
	ModeHelp         = "help"
	ModeSync         = "sync"
	ModeCommand      = "command"
	ModeFilter       = "filter"
)

Variables

View Source
var (
	KeymapCursorMoveDown1 = NewKeymapN([]string{"j"}, CommandCursorMoveDown).
							SetDesc("光标向下移动一行")
	KeymapCursorMoveDown2 = NewKeymapN([]string{tcell.KeyNames[tcell.KeyDown]}, CommandCursorMoveDown).
							SetDesc("光标向下移动一行")
	KeymapCursorMoveUp1 = NewKeymapN([]string{"k"}, CommandCursorMoveUp).
						SetDesc("光标向上移动一行")
	KeymapCursorMoveUp2 = NewKeymapN([]string{tcell.KeyNames[tcell.KeyUp]}, CommandCursorMoveUp).
						SetDesc("光标向上移动一行")

	KeymapEnter = NewKeymapN([]string{tcell.KeyNames[tcell.KeyEnter]}, CommandEnter).
				SetDesc("确定")

	KeymapInput = NewKeymapN([]string{""}, CommandInput).
				SetDesc("输入")

	KeymapBackspace1 = NewKeymapN([]string{tcell.KeyNames[tcell.KeyBackspace]}, CommandBackspace).
						SetDesc("退格")
	KeymapBackspace2 = NewKeymapN([]string{tcell.KeyNames[tcell.KeyBackspace2]}, CommandBackspace).
						SetDesc("退格")

	KeymapQuit1 = NewKeymapN([]string{tcell.KeyNames[tcell.KeyEscape]}, CommandQuit).
				SetDesc("退出")
	KeymapQuit2 = NewKeymapN([]string{tcell.KeyNames[tcell.KeyCtrlC]}, CommandQuit).
				SetDesc("退出")
	KeymapQuit3 = NewKeymapN([]string{"q"}, CommandQuit).
				SetDesc("退出")
	KeymapHelp = NewKeymapN([]string{"?"}, CommandHelp).
				SetDesc("帮助")

	NormalKeymaps = []Keymap{

		NewKeymapN([]string{"?"}, CommandHelp).SetDesc("帮助"),
		NewKeymapN([]string{"/"}, CommandFilter).SetDesc("过滤"),
		NewKeymapN([]string{"s"}, CommandSync).SetDesc("同步"),

		NewKeymapN([]string{","}, CommandSystem).SetDesc("文件源"),

		KeymapCursorMoveDown1,
		KeymapCursorMoveDown2,
		KeymapCursorMoveUp1,
		KeymapCursorMoveUp2,
		NewKeymapN([]string{"h"}, CommandGotoPrev).
			SetDesc("返回上一层目录"),
		NewKeymapN([]string{"G"}, CommandCursorMoveEnd).
			SetDesc("光标跳转到最后一行"),

		NewKeymapN(
			[]string{tcell.KeyNames[tcell.KeyCtrlD]},
			CommandCursorMoveHalfPageDown,
		).SetDesc("光标向下移动半页"),
		NewKeymapN(
			[]string{tcell.KeyNames[tcell.KeyCtrlU]},
			CommandCursorMoveHalfPageUp,
		).SetDesc("光标向上移动半页"),
		NewKeymapN(
			[]string{tcell.KeyNames[tcell.KeyCtrlF]},
			CommandCursorMovePageDown,
		).SetDesc("光标向下移动一页"),
		NewKeymapN(
			[]string{tcell.KeyNames[tcell.KeyCtrlB]},
			CommandCursorMovePageUp,
		).SetDesc("光标向上移动一页"),

		NewKeymapN([]string{"l"}, CommandEnter).
			SetDesc("选中文件,进入下一层目录或下载文件"),
		NewKeymapN([]string{tcell.KeyNames[tcell.KeyRight]}, CommandEnter).
			SetDesc("选中文件,进入下一层目录或下载文件"),
		NewKeymapN([]string{tcell.KeyNames[tcell.KeyEnter]}, CommandEnter).
			SetDesc("选中文件,进入下一层目录或下载文件"),
		NewKeymapN([]string{"x"}, CommandCutFile).
			SetDesc("剪切文件"),
		NewKeymapN([]string{"D"}, CommandDelete).
			SetDesc("删除文件"),
		NewKeymapN([]string{"d"}, CommandDownloadFile).
			SetDesc("下载文件"),
		NewKeymapN([]string{"R"}, CommandReload).
			SetDesc("重新加载目录"),
	}

	CommandKeymaps = []Keymap{
		KeymapEnter,
		KeymapBackspace1,
		KeymapBackspace2,
		KeymapQuit1,
		KeymapQuit2,
		KeymapQuit3,
	}

	SyncKeymaps = []Keymap{
		NewKeymapN([]string{"e"}, CommandSyncExec).
			SetDesc("执行同步"),
		KeymapEnter,
		KeymapCursorMoveDown1,
		KeymapCursorMoveDown2,
		KeymapCursorMoveUp1,
		KeymapCursorMoveUp2,
	}

	ConfirmKeymaps = []Keymap{
		NewKeymapN([]string{"y"}, CommandEnsure).
			SetDesc("确认"),
		NewKeymapN([]string{"h"}, CommandCursorMoveLeft).
			SetDesc("光标向左移动一个"),
		NewKeymapN([]string{"l"}, CommandCursorMoveRight).
			SetDesc("光标向右移动一个"),
	}

	HelpKeymaps = []Keymap{}

	CommonKeymaps = []Keymap{
		KeymapQuit1,
		KeymapQuit2,
		KeymapQuit3,
		KeymapHelp,
	}

	KeymapKeymaps = []Keymap{
		KeymapHelp,
		NewKeymapN([]string{"y", "d"}, CommandCopyDirpath).
			SetDesc("复制文件夹路径"),
		NewKeymapN([]string{"y", "n"}, CommandCopyFilename).
			SetDesc("复制文件名"),
		NewKeymapN([]string{"y", "p"}, CommandCopyFilepath).
			SetDesc("复制文件路径"),
		NewKeymapN([]string{"y", "y"}, CommandCopyFile).
			SetDesc("复制文件"),

		NewKeymapN([]string{"g", "g"}, CommandCursorMoveHome).
			SetDesc("移动光标到最上层"),
		NewKeymapN([]string{"g", "r"}, CommandGotoRoot).
			SetDesc("进入根目录"),

		NewKeymapN([]string{"p", "p"}, CommandPasteFile).SetDesc("粘贴文件"),
	}

	ModeKeymapsMap = map[Mode][]Keymap{
		ModeConfirm: ConfirmKeymaps,
		ModeNormal:  NormalKeymaps,
		ModeSync:    SyncKeymaps,
		ModeKeymap:  KeymapKeymaps,
	}
)
View Source
var (
	CacheSyncModelMap = make(map[string]*bdpan.SyncModel, 0)
)
View Source
var ErrActionFail = errors.New("操作失败")
View Source
var ErrFileExists = errors.New("文件已存在")
View Source
var ErrNoFileSelect = errors.New("请先选择文件")
View Source
var ErrNoTypeToPaste = errors.New("请先进行复制或剪切操作")
View Source
var ErrNotCopyFile = errors.New("请先使用 yy 复制文件")
View Source
var ErrQuit = errors.New("quit bdpan")
View Source
var (
	Log = bdpan.Log
)

Functions

func CanCacheError

func CanCacheError(e error) bool

func ConverFilesToSelectItems

func ConverFilesToSelectItems(s *terminal.Select, files []*bdpan.FileInfoDto) []*terminal.SelectItem

func FillCacheToSelect

func FillCacheToSelect(s *terminal.Select, dir, selectPath string) error

填充文件数据到 select 组件

func FillFileToSelect

func FillFileToSelect(s *terminal.Select, dir, selectPath string) error

填充文件数据到 select 组件

func FillSyncToSelect

func FillSyncToSelect(s *terminal.Select, file *bdpan.FileInfoDto) error

func FillSystemToSelect

func FillSystemToSelect(s *terminal.Select, action SystemAction) error

func FilterFileFiles

func FilterFileFiles(files []*bdpan.FileInfoDto) (filterFiles []*bdpan.FileInfoDto)

func GetAllCacheFiles

func GetAllCacheFiles() []*bdpan.FileInfoDto

func GetAllLocalFiles

func GetAllLocalFiles() (files []*bdpan.FileInfoDto, err error)

func GetCacheSelectIndex

func GetCacheSelectIndex(a SystemAction) (i int, f bool)

func GetRootFile

func GetRootFile() *bdpan.FileInfoDto

func GetSyncModelsByFilePath

func GetSyncModelsByFilePath(path string) []*bdpan.SyncModel

func IsInErrors

func IsInErrors(e error, errs []error) bool

func IsKeymapK

func IsKeymapK(k Keymap, key *tcell.EventKey) bool

func IsSync

func IsSync(file *bdpan.FileInfoDto) bool

func NewHelpItems

func NewHelpItems(m Mode) []terminal.HelpItem

func NewSystemSelectItem

func NewSystemSelectItem(icon, name string, action SystemAction) *terminal.SelectItem

func RefreshSyncModelCache

func RefreshSyncModelCache()

func SetCacheSelectIndex

func SetCacheSelectIndex(a SystemAction, i int)

Types

type BaseMode

type BaseMode struct {
	T            *terminal.Terminal
	Mode         Mode
	KeymapFn     KeymapFn
	Keymaps      []Keymap
	PrevEventKey *tcell.EventKey
	CurrEventKey *tcell.EventKey
	PrevCommand  Command
	SelectItems  []*terminal.SelectItem
}

func (*BaseMode) ClearPrevCommand

func (b *BaseMode) ClearPrevCommand()

func (*BaseMode) ClearSelectItems

func (b *BaseMode) ClearSelectItems()

func (*BaseMode) Draw

func (b *BaseMode) Draw() error

func (*BaseMode) GetKeymap

func (b *BaseMode) GetKeymap() Keymap

func (*BaseMode) GetKeymapFn

func (b *BaseMode) GetKeymapFn() KeymapFn

func (*BaseMode) GetKeymaps

func (b *BaseMode) GetKeymaps() []Keymap

func (BaseMode) GetMode

func (b BaseMode) GetMode() Mode

func (*BaseMode) GetPrevCommand

func (b *BaseMode) GetPrevCommand() Command

func (*BaseMode) GetSelectItems

func (b *BaseMode) GetSelectItems() []*terminal.SelectItem

func (*BaseMode) IsKey

func (b *BaseMode) IsKey(k Keymap) bool

func (*BaseMode) SetEventKey

func (b *BaseMode) SetEventKey(ev *tcell.EventKey)

func (*BaseMode) SetKeymapFn

func (b *BaseMode) SetKeymapFn(fn KeymapFn) *BaseMode

func (*BaseMode) SetKeymaps

func (b *BaseMode) SetKeymaps(k []Keymap) *BaseMode

func (*BaseMode) SetPrevCommand

func (b *BaseMode) SetPrevCommand(c Command)

func (*BaseMode) SetSelectItems

func (b *BaseMode) SetSelectItems(items []*terminal.SelectItem)

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(t *terminal.Terminal) *Client

func (*Client) ActionCopyMsg

func (c *Client) ActionCopyMsg(msg string) error

操作复制信息

func (*Client) ClearSelectFiles

func (c *Client) ClearSelectFiles() *Client

func (*Client) DisableCache

func (c *Client) DisableCache() *Client

func (*Client) DisableFilter

func (c *Client) DisableFilter() *Client

func (*Client) Download

func (c *Client) Download() error

func (*Client) Draw

func (c *Client) Draw() error

func (*Client) DrawCache

func (c *Client) DrawCache() error

func (*Client) DrawCacheNormal

func (c *Client) DrawCacheNormal() error

func (*Client) DrawCommand

func (c *Client) DrawCommand()

绘制命令界面

func (*Client) DrawConfirm

func (c *Client) DrawConfirm()

func (*Client) DrawDetail

func (c *Client) DrawDetail()

func (*Client) DrawInput

func (c *Client) DrawInput(prefix, text string)

绘制输入界面

func (*Client) DrawInputKey

func (c *Client) DrawInputKey()

绘制输入键位

func (*Client) DrawLeft

func (c *Client) DrawLeft() error

func (*Client) DrawMessage

func (c *Client) DrawMessage(text string)

绘制消息

func (*Client) DrawMid

func (c *Client) DrawMid() error

func (*Client) DrawMidData

func (c *Client) DrawMidData() error

func (*Client) DrawNormal

func (c *Client) DrawNormal() error

func (*Client) DrawTitle

func (c *Client) DrawTitle(text string)

绘制标题

func (*Client) EnableCache

func (c *Client) EnableCache() *Client

func (*Client) EnableModeNormal

func (c *Client) EnableModeNormal() *Client

func (*Client) Enter

func (c *Client) Enter() error

func (*Client) Exec

func (c *Client) Exec() error

func (*Client) GetLeftDir

func (c *Client) GetLeftDir() string

func (*Client) GetMidDir

func (c *Client) GetMidDir() string

func (*Client) GetMidSelectFile

func (c *Client) GetMidSelectFile() *bdpan.FileInfoDto

func (*Client) GetMidSelectItems

func (c *Client) GetMidSelectItems() []*terminal.SelectItem

func (*Client) GetMidSelectSystem

func (c *Client) GetMidSelectSystem() *SystemInfo

func (*Client) GetMode

func (c *Client) GetMode() Mode

func (*Client) GetModeDrawRange

func (c *Client) GetModeDrawRange() (StartX, StartY, EndX, EndY int)

func (*Client) GetModeNormalEndY

func (c *Client) GetModeNormalEndY() int

获取 normal 模式下模型 EndY

func (*Client) GetSelectFile

func (c *Client) GetSelectFile() *bdpan.FileInfoDto

func (*Client) HandleCommandKeymap

func (c *Client) HandleCommandKeymap(k Keymap) error

func (*Client) HandleCommonKeymap

func (c *Client) HandleCommonKeymap(k Keymap) error

func (*Client) HandleConfirmKeymap

func (c *Client) HandleConfirmKeymap(k Keymap) error

func (*Client) HandleEventKey

func (c *Client) HandleEventKey() error

func (*Client) HandleHelpKeymap

func (c *Client) HandleHelpKeymap(k Keymap) error

func (*Client) HandleKeymapKeymap

func (c *Client) HandleKeymapKeymap(k Keymap) error

func (*Client) HandleNormalKeymap

func (c *Client) HandleNormalKeymap(k Keymap) error

func (*Client) HandleSyncKeymap

func (c *Client) HandleSyncKeymap(k Keymap) error

func (*Client) IsKeymapK

func (c *Client) IsKeymapK(k Keymap) bool

func (*Client) MoveDown

func (c *Client) MoveDown(step int)

func (*Client) MoveLeft

func (c *Client) MoveLeft()

func (*Client) MoveUp

func (c *Client) MoveUp(step int)

func (*Client) NewNormalMode

func (c *Client) NewNormalMode() *NormalMode

func (*Client) RefreshUsed

func (c *Client) RefreshUsed() error

刷新网盘使用情况

func (*Client) SetCommandMode

func (c *Client) SetCommandMode(nextMode ModeInterface) *Client

--------------------------- CommandMode ---------------------------

func (*Client) SetConfirmMode

func (c *Client) SetConfirmMode(ensureC Command, msg string) *Client

--------------------------- ConfirmMode ---------------------------

func (*Client) SetCurrSelectFiles

func (c *Client) SetCurrSelectFiles() *Client

func (*Client) SetHelpMode

func (c *Client) SetHelpMode() *Client

--------------------------- HelpMode ---------------------------

func (*Client) SetKeymapMode

func (c *Client) SetKeymapMode() *Client

--------------------------- KeymapMode ---------------------------

func (*Client) SetM

func (c *Client) SetM(m ModeInterface) *Client

func (*Client) SetMidFile

func (c *Client) SetMidFile(file *bdpan.FileInfoDto) *Client

func (*Client) SetMode

func (c *Client) SetMode(m Mode) *Client

func (*Client) SetNormalAction

func (c *Client) SetNormalAction(a SystemAction) *Client

func (*Client) SetNormalMode

func (c *Client) SetNormalMode() *Client

--------------------------- NormalMode ---------------------------

func (*Client) SetSelectItems

func (c *Client) SetSelectItems() *Client

func (*Client) SetSyncMode

func (c *Client) SetSyncMode() *Client

--------------------------- SyncMode ---------------------------

func (*Client) SetUser

func (c *Client) SetUser(u *bdpan.UserInfoDto) *Client

func (*Client) ShowSystem

func (c *Client) ShowSystem()

func (Client) Size

func (c Client) Size() (w, h int)

type Command

type Command string

type CommandFn

type CommandFn func(Command) error

type CommandMode

type CommandMode struct {
	*BaseMode
	NextMode ModeInterface
	Prefix   string
	Input    string
}

func NewCommandMode

func NewCommandMode(prefix string) *CommandMode

func (*CommandMode) GetKeymap

func (c *CommandMode) GetKeymap() Keymap

func (*CommandMode) SetInput

func (m *CommandMode) SetInput(t string) *CommandMode

func (*CommandMode) SetNextMode

func (m *CommandMode) SetNextMode(mi ModeInterface) *CommandMode

type ConfirmMode

type ConfirmMode struct {
	*BaseMode
	Msg           string
	Term          *terminal.Confirm
	EnsureCommand Command
}

func NewConfirmMode

func NewConfirmMode(t *terminal.Terminal, ensureC Command, msg string) *ConfirmMode

type DownloadCommand

type DownloadCommand struct {
	From        string
	OutputDir   string
	OutputPath  string
	IsSync      bool
	IsRecursion bool
	IsVerbose   bool
}

func (DownloadCommand) Download

func (d DownloadCommand) Download(file *bdpan.FileInfoDto) error

func (DownloadCommand) Run

func (d DownloadCommand) Run() error

type FileInfo

type FileInfo struct {
	*bdpan.FileInfoDto
	MaxTextWidth int
	IsSync       bool
	Count        int
}

func (FileInfo) Name

func (i FileInfo) Name() string

func (FileInfo) String

func (i FileInfo) String() string

type FileSelectCache

type FileSelectCache struct {
	Dir         string
	Files       []*bdpan.FileInfoDto
	SelectIndex int
}

func GetFileSelectCache

func GetFileSelectCache(dir string) *FileSelectCache

func NewFileSelectCache

func NewFileSelectCache(dir string, s *terminal.Select, files []*bdpan.FileInfoDto) *FileSelectCache

func (*FileSelectCache) Save

func (f *FileSelectCache) Save()

type HelpMode

type HelpMode struct {
	*BaseMode
	Term *terminal.Help
}

func NewHelpMode

func NewHelpMode(
	t *terminal.Terminal, fromMode Mode,
	StartX, StartY, EndX, EndY int,
) *HelpMode

------------------------------

HelpMode

------------------------------

func (*HelpMode) Draw

func (h *HelpMode) Draw() error

type Keymap

type Keymap struct {
	R             rune
	Key           tcell.Key
	Keys          []string
	Command       Command
	CommandString string
	Msg           string
	Desc          string
	RelKeys       []Keymap
}

func NewKeymapN

func NewKeymapN(keys []string, c Command) Keymap

func (Keymap) AddRelKey

func (k Keymap) AddRelKey(km Keymap) Keymap

func (Keymap) GetKey

func (k Keymap) GetKey() string

func (Keymap) IsKey

func (k Keymap) IsKey(currEK *tcell.EventKey, prevEK *tcell.EventKey) bool

func (Keymap) IsNil

func (k Keymap) IsNil() bool

func (Keymap) SetCommandString

func (k Keymap) SetCommandString(c string) Keymap

func (Keymap) SetDesc

func (k Keymap) SetDesc(d string) Keymap

type KeymapAction

type KeymapAction int

type KeymapFn

type KeymapFn func(Keymap) error

type KeymapMode

type KeymapMode struct {
	*BaseMode
	Term *terminal.List
}

func NewKeymapMode

func NewKeymapMode(t *terminal.Terminal, currEK *tcell.EventKey) *KeymapMode

------------------------------

KeymapMode

------------------------------

func (*KeymapMode) Draw

func (k *KeymapMode) Draw() error

type Mode

type Mode string

type ModeInterface

type ModeInterface interface {
	GetMode() Mode
	GetKeymapFn() KeymapFn
	GetKeymaps() []Keymap
	GetKeymap() Keymap
	SetEventKey(ev *tcell.EventKey)
	IsKey(Keymap) bool
	Draw() error
	ClearPrevCommand()
	SetPrevCommand(c Command)
	GetPrevCommand() Command
	ClearSelectItems()
	SetSelectItems([]*terminal.SelectItem)
	GetSelectItems() []*terminal.SelectItem
}

type NormalMode

type NormalMode struct {
	*BaseMode
}

func NewNormalMode

func NewNormalMode() *NormalMode

func (*NormalMode) GetKeymap

func (n *NormalMode) GetKeymap() Keymap

type SyncInfo

type SyncInfo struct {
	*bdpan.SyncModel
	MaxTextWidth int
}

func (SyncInfo) Name

func (i SyncInfo) Name() string

func (SyncInfo) String

func (i SyncInfo) String() string

type SyncMode

type SyncMode struct {
	*BaseMode
	Term       *terminal.Select
	SelectItem *terminal.SelectItem
}

func NewSyncMode

func NewSyncMode(
	t *terminal.Terminal, item *terminal.SelectItem,
	StartX, StartY, EndX, EndY int,
) *SyncMode

------------------------------

SyncMode

------------------------------

func (*SyncMode) Count

func (s *SyncMode) Count() int

func (*SyncMode) Draw

func (s *SyncMode) Draw() error

type SystemAction

type SystemAction int
const (
	ActionSystem SystemAction = iota
	ActionFile
	ActionBigFile
	ActionSync
)

type SystemInfo

type SystemInfo struct {
	Icon   string
	Action SystemAction
	// contains filtered or unexported fields
}

func (SystemInfo) Name

func (i SystemInfo) Name() string

func (SystemInfo) String

func (i SystemInfo) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL