Add quit confirmation for modified document
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
This commit is contained in:
parent
799af21a24
commit
42e50dfebb
@ -4,5 +4,8 @@ package editor
|
|||||||
// !Constants
|
// !Constants
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
const KiloVersion = "0.0.1"
|
const (
|
||||||
const KiloTabStop = 4
|
KiloVersion = "0.0.1"
|
||||||
|
KiloTabStop = 4
|
||||||
|
KiloQuitTimes = 3
|
||||||
|
)
|
||||||
|
@ -27,6 +27,7 @@ type editor struct {
|
|||||||
offset *point
|
offset *point
|
||||||
document *document
|
document *document
|
||||||
status *statusMsg
|
status *statusMsg
|
||||||
|
quitTimes uint8
|
||||||
renderX int
|
renderX int
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +51,7 @@ func New() *editor {
|
|||||||
offset,
|
offset,
|
||||||
document,
|
document,
|
||||||
status,
|
status,
|
||||||
|
KiloQuitTimes,
|
||||||
0,
|
0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,6 +82,13 @@ func (e *editor) ProcessKeypress() bool {
|
|||||||
|
|
||||||
switch ch {
|
switch ch {
|
||||||
case key.Ctrl('q'):
|
case key.Ctrl('q'):
|
||||||
|
if e.document.dirty && e.quitTimes > 0 {
|
||||||
|
e.SetStatusMessage("WARNING!!! File has unsaved changes. Press Ctrl-Q %d more tiems to quite.", e.quitTimes)
|
||||||
|
e.quitTimes -= 1
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Clean up on exit
|
// Clean up on exit
|
||||||
terminal.Write(terminal.ClearScreen + terminal.ResetCursor)
|
terminal.Write(terminal.ClearScreen + terminal.ResetCursor)
|
||||||
|
|
||||||
@ -113,6 +122,10 @@ func (e *editor) ProcessKeypress() bool {
|
|||||||
e.insertChar(ch)
|
e.insertChar(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.quitTimes != KiloQuitTimes {
|
||||||
|
e.quitTimes = KiloQuitTimes
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user