From 30b4c3818a404eefaa89042748373e8f4298f461 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 9 Apr 2021 16:27:16 -0400 Subject: [PATCH] Continue refactoring of non-PHP syntax highlighting --- src/Editor.php | 11 +++++++++-- src/Row.php | 14 ++++++++------ src/Terminal.php | 8 ++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Editor.php b/src/Editor.php index 9320bca..fe579a2 100644 --- a/src/Editor.php +++ b/src/Editor.php @@ -772,10 +772,11 @@ class Editor { { $this->document->delete($this->cursor); } - else if ($ch === KeyType::BACKSPACE && ($this->cursor->x > 0 || $this->cursor->y > 0)) + + if ($ch === KeyType::BACKSPACE && ($this->cursor->x > 0 || $this->cursor->y > 0)) { - $this->document->delete($this->cursor); $this->moveCursor(KeyType::ARROW_LEFT); + $this->document->delete($this->cursor); } } @@ -783,10 +784,16 @@ class Editor { { if ($this->document->isDirty() && $this->quitTimes > 0) { + if ($this->quitTimes === KILO_QUIT_TIMES) + { + Terminal::ding(); + } + $this->setStatusMessage( 'WARNING!!! File has unsaved changes. Press Ctrl-Q %d more times to quit.', $this->quitTimes ); + $this->quitTimes--; return; } diff --git a/src/Row.php b/src/Row.php index 823f67a..85a2da8 100644 --- a/src/Row.php +++ b/src/Row.php @@ -219,12 +219,14 @@ class Row { return; } - $keywords1 = $this->parent->fileType->syntax->keywords1; - $keywords2 = $this->parent->fileType->syntax->keywords2; + $syntax = $this->parent->fileType->syntax; - $scs = $this->parent->fileType->syntax->singleLineCommentStart; - $mcs = $this->parent->fileType->syntax->multiLineCommentStart; - $mce = $this->parent->fileType->syntax->multiLineCommentEnd; + $keywords1 = $syntax->keywords1; + $keywords2 = $syntax->keywords2; + + $scs = $syntax->singleLineCommentStart; + $mcs = $syntax->multiLineCommentStart; + $mce = $syntax->multiLineCommentEnd; $scsLen = strlen($scs); $mcsLen = strlen($mcs); @@ -281,7 +283,7 @@ class Row { $this->highlightString($i); // Numbers, including decimal points - if ($this->parent->fileType->syntax->flags & Syntax::HIGHLIGHT_NUMBERS) + if ($syntax->flags & Syntax::HIGHLIGHT_NUMBERS) { if ( ($char === '.' && $prevHl === Highlight::NUMBER) || diff --git a/src/Terminal.php b/src/Terminal.php index 2ff37b1..b6e85ff 100644 --- a/src/Terminal.php +++ b/src/Terminal.php @@ -115,6 +115,14 @@ class Terminal { }; } + /** + * Ring the terminal bell + */ + public static function ding(): void + { + self::write(RawKeyCode::BELL); + } + /** * Write to the stdout stream *