edit: Make it more user-friendly
This commit is contained in:
parent
5c2718545f
commit
65834ff491
@ -1,6 +1,8 @@
|
||||
#include <luna/String.h>
|
||||
#include <os/ArgumentParser.h>
|
||||
#include <os/File.h>
|
||||
#include <os/FileSystem.h>
|
||||
#include <os/Prompt.h>
|
||||
|
||||
using os::File;
|
||||
|
||||
@ -14,10 +16,20 @@ Result<int> luna_main(int argc, char** argv)
|
||||
parser.add_positional_argument(pathname, "path"_sv, true);
|
||||
parser.parse(argc, argv);
|
||||
|
||||
if (os::FileSystem::exists(pathname))
|
||||
{
|
||||
String prompt = TRY(String::format("File %s already exists. Overwrite?"_sv, pathname.chars()));
|
||||
bool overwrite = os::conditional_prompt(prompt.chars(), os::DefaultNo);
|
||||
if (!overwrite) return 0;
|
||||
}
|
||||
|
||||
auto file = TRY(File::open_or_create(pathname, File::WriteOnly));
|
||||
|
||||
auto input = File::standard_input();
|
||||
|
||||
os::println("- Editing %s. Press Enter to start a new line, or Ctrl+D at the start of a line to save and exit. -",
|
||||
pathname.chars());
|
||||
|
||||
while (1)
|
||||
{
|
||||
String line = TRY(input->read_line());
|
||||
|
Loading…
Reference in New Issue
Block a user