Ugly progress commit

This commit is contained in:
Timothy Warren 2019-10-22 16:44:55 -04:00
parent 98a3b8b691
commit 5642187c0e

View File

@ -71,6 +71,11 @@ class Row {
} }
} }
public function __toString(): string
{
return $this->chars . "\n";
}
public function update(): void public function update(): void
{ {
$idx = 0; $idx = 0;
@ -393,33 +398,35 @@ class Editor {
protected function rowsToString(): string protected function rowsToString(): string
{ {
$str = ''; $lines = [];
foreach ($this->rows as $row) foreach ($this->rows as $row)
{ {
$str .= $row->chars . "\n"; $lines[] = (string)$row;
} }
return $str; return implode('', $lines);
} }
public function open(string $filename): void public function open(string $filename): void
{ {
// Copy filename for display
$this->filename = $filename;
// Determine the full path to the file // Determine the full path to the file
$baseFile = basename($filename); /* $baseFile = basename($filename);
$basePath = str_replace($baseFile, '', $filename); $basePath = str_replace($baseFile, '', $filename);
$path = (is_dir($basePath)) ? $basePath : getcwd(); $path = (is_dir($basePath)) ? $basePath : getcwd();
$fullname = $path . '/' . $baseFile; $fullname = $path . '/' . $baseFile; */
// Copy filename for display
$this->filename = $fullname;
// #TODO gracefully handle issues with loading a file // #TODO gracefully handle issues with loading a file
$handle = fopen($fullname, 'rb'); $handle = fopen($filename, 'rb');
if ($handle === FALSE) if ($handle === FALSE)
{ {
write_stdout("\x1b[2J"); // Clear the screen
write_stdout("\x1b[H"); // Reposition cursor to top-left
disableRawMode(); disableRawMode();
print_r(error_clear_last()); print_r(error_get_last());
die(); die();
} }
@ -438,12 +445,14 @@ class Editor {
{ {
if ($this->filename === '') if ($this->filename === '')
{ {
$this->filename = $this->prompt('Save as: %s'); $newFilename = $this->prompt('Save as: %s');
if ($this->filename === '') if ($newFilename === '')
{ {
$this->setStatusMessage('Save aborted'); $this->setStatusMessage('Save aborted');
return; return;
} }
$this->filename = $newFilename;
} }
$contents = $this->rowsToString(); $contents = $this->rowsToString();