Documentation ¶
Index ¶
- Constants
- func PrintList[T any](ops ConsoleOperations, title string, items []T, maxItemsDisplay int)
- type BatchCreateTableSession
- type ConsoleGlue
- type ConsoleOperations
- func (ops ConsoleOperations) CreateTable() *Table
- func (ops ConsoleOperations) GetWidth() int
- func (ops ConsoleOperations) IsInteractive() bool
- func (ops ConsoleOperations) OutputIsTTY() bool
- func (ops ConsoleOperations) Print(args ...any)
- func (ops ConsoleOperations) Printf(format string, args ...any)
- func (ops ConsoleOperations) Println(args ...any)
- func (ops ConsoleOperations) PromptBool(p string) bool
- func (ops ConsoleOperations) RootFrame() Frame
- func (ops ConsoleOperations) Scanln(args ...any) (int, error)
- func (ops ConsoleOperations) ShowTask(message string, extraFields ...ExtraField) func()
- func (ops ConsoleOperations) StartProgressBar(title string, total int, extraFields ...ExtraField) ProgressWaiter
- type ExtraField
- type Frame
- type Glue
- type GlueClient
- type NoOPConsoleGlue
- type PrettyString
- type Progress
- type ProgressWaiter
- type Session
- type StdIOGlue
- type Table
Constants ¶
const OnlyOneTask int = -1
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BatchCreateTableSession ¶
type BatchCreateTableSession interface { CreateTables(ctx context.Context, tables map[string][]*model.TableInfo, cs ...ddl.CreateTableOption) error }
BatchCreateTableSession is an interface to batch create table parallelly
type ConsoleGlue ¶
type ConsoleGlue interface { // Out returns the output port of the console. Out() io.Writer // In returns the input of the console. // Usually is should be an *os.File. In() io.Reader }
ConsoleGlue is the glue between BR and some type of console, which is the port for interact with the user. Generally, this is a abstraction of an UNIX terminal.
type ConsoleOperations ¶
type ConsoleOperations struct {
ConsoleGlue
}
ConsoleOperations are some operations based on ConsoleGlue.
func GetConsole ¶
func GetConsole(g Glue) ConsoleOperations
func (ConsoleOperations) CreateTable ¶
func (ops ConsoleOperations) CreateTable() *Table
func (ConsoleOperations) GetWidth ¶
func (ops ConsoleOperations) GetWidth() int
func (ConsoleOperations) IsInteractive ¶
func (ops ConsoleOperations) IsInteractive() bool
func (ConsoleOperations) OutputIsTTY ¶
func (ops ConsoleOperations) OutputIsTTY() bool
func (ConsoleOperations) Print ¶
func (ops ConsoleOperations) Print(args ...any)
func (ConsoleOperations) Printf ¶
func (ops ConsoleOperations) Printf(format string, args ...any)
func (ConsoleOperations) Println ¶
func (ops ConsoleOperations) Println(args ...any)
func (ConsoleOperations) PromptBool ¶
func (ops ConsoleOperations) PromptBool(p string) bool
PromptBool prompts a boolean from the user.
func (ConsoleOperations) RootFrame ¶
func (ops ConsoleOperations) RootFrame() Frame
func (ConsoleOperations) ShowTask ¶
func (ops ConsoleOperations) ShowTask(message string, extraFields ...ExtraField) func()
ShowTask prints a task start information, and mark as finished when the returned function called. This is for TUI presenting.
func (ConsoleOperations) StartProgressBar ¶
func (ops ConsoleOperations) StartProgressBar(title string, total int, extraFields ...ExtraField) ProgressWaiter
StartProgressBar starts a progress bar with the console operations. Note: This function has overlapped function with `glue.StartProgress`, however this supports display extra fields
after success, and implement by `mpb` (instead of `pb`).
Note': Maybe replace the old `StartProgress` with `mpb` too.
type ExtraField ¶
type ExtraField func() [2]string
An extra field appending to the task. return type is a {key: string, value: string} tuple.
func WithCallbackExtraField ¶
func WithCallbackExtraField(key string, value func() string) ExtraField
WithCallbackExtraField adds an extra field with the callback.
func WithConstExtraField ¶
func WithConstExtraField(key string, value any) ExtraField
WithConstExtraField adds an extra field with constant values.
func WithTimeCost ¶
func WithTimeCost() ExtraField
WithTimeCost adds the task information of time costing for `ShowTask`.
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is an fix-width place for printing. It is the abstraction of some subarea of the terminal, you might imagine it as a panel in the tmux, but with infinity height. For example, printing a frame with the width of 10 chars, and 4 chars offset left, would be like:
v~~~~~~~~~~v Here is the "width of a frame".
+--+----------+--+ | Hello, wor | | ld. | +--+----------+--+ ^~~^ Here is the "offset of a frame".
func (Frame) OffsetLeftWithMinWidth ¶
func (Frame) Print ¶
func (f Frame) Print(s PrettyString)
type Glue ¶
type Glue interface { GetDomain(store kv.Storage) (*domain.Domain, error) CreateSession(store kv.Storage) (Session, error) Open(path string, option pd.SecurityOption) (kv.Storage, error) // OwnsStorage returns whether the storage returned by Open() is owned // If this method returns false, the connection manager will never close the storage. OwnsStorage() bool StartProgress(ctx context.Context, cmdName string, total int64, redirectLog bool) Progress // Record records some information useful for log-less summary. Record(name string, value uint64) // GetVersion gets BR package version to run backup/restore job GetVersion() string // UseOneShotSession temporary creates session from store when run backup job. // because we don't have to own domain/session during the whole backup. // we can close domain as soon as possible. // and we must reuse the exists session and don't close it in SQL backup job. UseOneShotSession(store kv.Storage, closeDomain bool, fn func(se Session) error) error // GetClient returns the client type of the glue GetClient() GlueClient }
Glue is an abstraction of TiDB function calls used in BR.
type NoOPConsoleGlue ¶
type NoOPConsoleGlue struct{}
NoOPConsoleGlue is the glue for "embedded" BR, say, BRIE via SQL. This Glue simply drop all console operations.
func (NoOPConsoleGlue) In ¶
func (NoOPConsoleGlue) In() io.Reader
func (NoOPConsoleGlue) Out ¶
func (NoOPConsoleGlue) Out() io.Writer
type PrettyString ¶
type PrettyString struct {
// contains filtered or unexported fields
}
PrettyString is a string with ANSI escape sequence which would change its color. this wrapper can help to do some operations over those string.
func NewPrettyString ¶
func NewPrettyString(s string) PrettyString
NewPrettyString wraps a string with ANSI escape seuqnces with PrettyString.
func (PrettyString) Len ¶
func (ps PrettyString) Len() int
Len returns the length of the string with removal of all ANSI sequences. ("The raw length") . Example: "\e[38;5;226mhello, world\e[0m".Len() => 12 Note: The length of golden string "hello, world" is 12.
func (PrettyString) Pretty ¶
func (ps PrettyString) Pretty() string
Pretty returns the pretty form of the string: with keeping all ANSI escape sequences. Example: "\e[38;5;226mhello, world\e[0m".Pretty() => "\e[38;5;226mhello, world\e[0m"
func (PrettyString) Raw ¶
func (ps PrettyString) Raw() string
Raw returns the raw form of the pretty string: with removal of all ANSI escape sequences. Example: "\e[38;5;226mhello, world\e[0m".Raw() => "hello, world"
func (PrettyString) SplitAt ¶
func (ps PrettyString) SplitAt(n int) (left, right PrettyString)
SplitAt splits a pretty string at the place and ignoring all formats. Example: "\e[38;5;226mhello, world\e[0m".SplitAt(5) => ["\e[38;5;226mhello", ", world\e[0m"]
type Progress ¶
type Progress interface { // Inc increases the progress. This method must be goroutine-safe, and can // be called from any goroutine. Inc() // IncBy increases the progress by cnt. This method must be goroutine-safe, and can // be called from any goroutine. IncBy(cnt int64) // GetCurrent reports the progress. GetCurrent() int64 // Close marks the progress as 100% complete and that Inc() can no longer be // called. Close() }
Progress is an interface recording the current execution progress.
type ProgressWaiter ¶
ProgressWaiter is the extended `Progress“: which provides a `wait` method to allow caller wait until all unit in the progress finished.
type Session ¶
type Session interface { Execute(ctx context.Context, sql string) error ExecuteInternal(ctx context.Context, sql string, args ...any) error CreateDatabase(ctx context.Context, schema *model.DBInfo) error CreateTable(ctx context.Context, dbName pmodel.CIStr, table *model.TableInfo, cs ...ddl.CreateTableOption) error CreatePlacementPolicy(ctx context.Context, policy *model.PolicyInfo) error Close() GetGlobalVariable(name string) (string, error) GetSessionCtx() sessionctx.Context }
Session is an abstraction of the session.Session interface.
type StdIOGlue ¶
type StdIOGlue struct{}
StdIOGlue is the console glue for CLI applications, like the BR CLI.