changeset 3:a79a840691b1

handle args
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 31 Mar 2025 17:17:38 -0600
parents f38f6e903369
children 3d6414265959
files dev.sh editor.luan
diffstat 2 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
diff -r f38f6e903369 -r a79a840691b1 dev.sh
--- a/dev.sh	Mon Mar 31 17:00:20 2025 -0600
+++ b/dev.sh	Mon Mar 31 17:17:38 2025 -0600
@@ -1,1 +1,1 @@
-java -Xdock:name="Luan Editor" -classpath $CLASSPATH luan.Luan editor.luan 2> >(grep -v 'openAndSavePanelService' >&2)
+java -Xdock:name="Luan Editor" -classpath $CLASSPATH luan.Luan editor.luan "$@" 2> >(grep -v 'openAndSavePanelService' >&2)
diff -r f38f6e903369 -r a79a840691b1 editor.luan
--- a/editor.luan	Mon Mar 31 17:00:20 2025 -0600
+++ b/editor.luan	Mon Mar 31 17:17:38 2025 -0600
@@ -1,7 +1,9 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
+local ipairs = Luan.ipairs or error()
 local Io = require "luan:Io.luan"
 local print = Io.print or error()
+local new_file = Io.schemes.file or error()
 local Swing = require "luan:swing/Swing.luan"
 local new_frame = require("luan:swing/Frame.luan").new or error()
 local new_label = require("luan:swing/Label.luan").new or error()
@@ -62,7 +64,7 @@
 
 function new_window(file)
 	local frame = new_frame()
-	frame.title = file and file.to_string() or "untitled"
+	frame.title = file and file.canonical().to_string() or "untitled"
 	frame.add_close_listener(function()
 		n_windows = n_windows - 1
 		if n_windows == 0 then
@@ -70,7 +72,7 @@
 		end
 	end)
 	local text_area = new_text_area()
-	if file ~= nil then
+	if file ~= nil and file.is_file() then
 		text_area.text = file.read_text()
 	end
 	text_area.rows = 10
@@ -102,5 +104,13 @@
 end
 
 Swing.run(function()
-	new_window()
+	local args = Luan.arg
+	if #args == 0 then
+		new_window()
+	else
+		for _, arg in ipairs(args) do
+			local file = new_file(arg)
+			new_window(file)
+		end
+	end
 end)