frontend

package
v0.0.0-...-f9952bb Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AprilshMsgOpen     = "open aprilsh:"
	AprishMsgClose     = "close aprilsh:"
	AprilshPackageName = "aprilsh"
	CommandServerName  = "apshd"
	CommandClientName  = "apsh"
	TimeoutIfNoResp    = 60000
	TimeoutIfNoConnect = 15000

	VersionInfo = `` /* 283-byte string literal not displayed */

)
View Source
const (
	SEND_INTERVAL_MIN    = 20    /* ms between frames */
	SEND_INTERVAL_MAX    = 250   /* ms between frames */
	ACK_INTERVAL         = 3000  /* ms between empty acks */
	ACK_DELAY            = 100   /* ms before delayed ack */
	SHUTDOWN_RETRIES     = 16    /* number of shutdown packets to send before giving up */
	ACTIVE_RETRY_TIMEOUT = 10000 /* attempt to resend at frame rate */
)
View Source
const (
	SRTT_TRIGGER_LOW          = 20   // <= ms cures SRTT trigger to show predictions
	SRTT_TRIGGER_HIGH         = 30   // > ms starts SRTT trigger
	FLAG_TRIGGER_LOW          = 50   // <= ms cures flagging
	FLAG_TRIGGER_HIGH         = 80   // > ms starts flagging
	GLITCH_THRESHOLD          = 250  // prediction outstanding this long is glitch
	GLITCH_REPAIR_COUNT       = 10   // non-glitches required to cure glitch trigger
	GLITCH_REPAIR_MININTERVAL = 150  // required time in between non-glitches
	GLITCH_FLAG_THRESHOLD     = 5000 // prediction outstanding this long => underline
)
View Source
const (
	MAX_SIGNAL_NUMBER = 64
)

Variables

View Source
var (
	GitTag      string // build version
	GoVersion   string // Go version
	BuildTime   string // build time
	GitCommit   string // git commit id
	GitBranch   string // git branch name
	DefaultPort = 8100 // https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
)

Functions

func DecodeTerminalCaps

func DecodeTerminalCaps(str []byte) (map[int]string, error)

func EncodeTerminalCaps

func EncodeTerminalCaps(caps map[int]string) []byte

func PrintUsage

func PrintUsage(hint string, usage ...string)

func PrintVersion

func PrintVersion()

func ReadFromFile

func ReadFromFile(timeout int, msgChan chan Message, doneChan chan any, fReader io.Reader)

Read from the reader, set read time out for every read. The read result will be sent to caller via msgChan, including error info if available. doneChan channel is used to stop the file reader.

Note the caller should consume the last read message when shutdown.

func ReadFromNetwork

func ReadFromNetwork(timeout int, msgChan chan Message, doneChan chan any, connection Connection)

Read from the network, set read time out before every read. The read result will be sent to caller via msgChan, including error info if available. doneChan channel is used to stop the network receiver.

Note the caller should consume the last read message when shutdown. connection closed error will stop the function.

Types

type Connection

type Connection interface {
	Recv(timeout int) (payload string, rAddr net.Addr, err error)
}

for easy mock

type DisplayPreference

type DisplayPreference uint
const (
	DisplayPreferenceUnused DisplayPreference = iota
	Always
	Never // disable the prediction
	Adaptive
	Experimental
)

type Message

type Message struct {
	RAddr net.Addr // if the message is from network, it's the remote address
	Err   error    // error if it happens
	Data  string   // payload data
}

communication the read result with the others

type NotificationEngine

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

func (*NotificationEngine) ClearNetworkError

func (ne *NotificationEngine) ClearNetworkError()

extend message expire time 1 second later, if it's network message error.

func (*NotificationEngine) GetNotificationString

func (ne *NotificationEngine) GetNotificationString() string

func (*NotificationEngine) ServerAcked

func (ne *NotificationEngine) ServerAcked(ts int64)

set first sent state timestamp, when network input happens

func (*NotificationEngine) ServerHeard

func (ne *NotificationEngine) ServerHeard(ts int64)

set latest received state timestamp, when network input happens or shutdown

func (*NotificationEngine) SetEscapeKeyString

func (ne *NotificationEngine) SetEscapeKeyString(str string)

func (*NotificationEngine) SetNetworkError

func (ne *NotificationEngine) SetNetworkError(str string)

set (network error) message and message expire time, message expires 3.1 seconds later.

func (*NotificationEngine) SetNotificationString

func (ne *NotificationEngine) SetNotificationString(message string, permanent bool, showQuitKeystroke bool)

set message and message expire time, if permanent is true, message expire time is forever. if permanent is false, message expires 1 second later. also set showQuitKeystroke.

type OverlayManager

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

func NewOverlayManager

func NewOverlayManager() *OverlayManager

func (*OverlayManager) Apply

func (om *OverlayManager) Apply(emu *terminal.Emulator)

func (*OverlayManager) GetNotificationEngine

func (om *OverlayManager) GetNotificationEngine() *NotificationEngine

func (*OverlayManager) GetPredictionEngine

func (om *OverlayManager) GetPredictionEngine() *PredictionEngine

func (*OverlayManager) SetTitlePrefix

func (om *OverlayManager) SetTitlePrefix(v string)

func (*OverlayManager) WaitTime

func (om *OverlayManager) WaitTime() int

type PredictionEngine

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

predict cursor movement and user input

func (*PredictionEngine) ClearApplied

func (pe *PredictionEngine) ClearApplied()

func (*PredictionEngine) GetApplied

func (pe *PredictionEngine) GetApplied() string

func (*PredictionEngine) IsApplied

func (pe *PredictionEngine) IsApplied() bool

func (*PredictionEngine) NewUserInput

func (pe *PredictionEngine) NewUserInput(emu *terminal.Emulator, input []rune, ptime ...int64)

when user input happens, set last sent state number before callling this method, this method validate previous predictions (cull), then use new input to prepare for new prediction. prepare for new prediction means updating prediction overlays, which involve cells and cursors.

a.k.a mosh new_user_byte() method

func (*PredictionEngine) Reset

func (pe *PredictionEngine) Reset()

clear the whole predictions, start new epoch.

func (*PredictionEngine) SetDisplayPreference

func (pe *PredictionEngine) SetDisplayPreference(v DisplayPreference)

set displayPreference when init

func (*PredictionEngine) SetLocalFrameAcked

func (pe *PredictionEngine) SetLocalFrameAcked(v uint64)

when network input happens, set first sent state num

func (*PredictionEngine) SetLocalFrameLateAcked

func (pe *PredictionEngine) SetLocalFrameLateAcked(v uint64)

when network input happens, set last received remote state acked num

func (*PredictionEngine) SetLocalFrameSent

func (pe *PredictionEngine) SetLocalFrameSent(v uint64)

when user input happens, set last sent state num

func (*PredictionEngine) SetPredictOverwrite

func (pe *PredictionEngine) SetPredictOverwrite(overwrite bool)

set predictOverwrite when init.

func (*PredictionEngine) SetSendInterval

func (pe *PredictionEngine) SetSendInterval(value uint)

when network input happens, set send interval

type Signals

func (*Signals) AnySignal

func (s *Signals) AnySignal() (rv bool)

Check whether we got any signal. This method DOES NOT consumes any signal notification.

func (*Signals) Clear

func (s *Signals) Clear()

clear all the signals

func (*Signals) GotSignal

func (s *Signals) GotSignal(x syscall.Signal) (ret bool)

Check whether we got the spcified signal. If so return true, otherwise false. This method consumes a signal notification.

func (*Signals) Handler

func (s *Signals) Handler(signal os.Signal)

handle the signal by store it in Signals array.

type TitleEngine

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

represent the prediction title prefix.

type Validity

type Validity uint
const (
	ValidityUnused Validity = iota
	Pending
	Correct
	CorrectNoCredit
	IncorrectOrExpired
	Inactive
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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