Mercurial Hosting > editor
comparison editor.luan @ 3:a79a840691b1
handle args
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Mon, 31 Mar 2025 17:17:38 -0600 |
| parents | f38f6e903369 |
| children | 3d6414265959 |
comparison
equal
deleted
inserted
replaced
| 2:f38f6e903369 | 3:a79a840691b1 |
|---|---|
| 1 local Luan = require "luan:Luan.luan" | 1 local Luan = require "luan:Luan.luan" |
| 2 local error = Luan.error | 2 local error = Luan.error |
| 3 local ipairs = Luan.ipairs or error() | |
| 3 local Io = require "luan:Io.luan" | 4 local Io = require "luan:Io.luan" |
| 4 local print = Io.print or error() | 5 local print = Io.print or error() |
| 6 local new_file = Io.schemes.file or error() | |
| 5 local Swing = require "luan:swing/Swing.luan" | 7 local Swing = require "luan:swing/Swing.luan" |
| 6 local new_frame = require("luan:swing/Frame.luan").new or error() | 8 local new_frame = require("luan:swing/Frame.luan").new or error() |
| 7 local new_label = require("luan:swing/Label.luan").new or error() | 9 local new_label = require("luan:swing/Label.luan").new or error() |
| 8 local new_text_area = require("luan:swing/Text_area.luan").new or error() | 10 local new_text_area = require("luan:swing/Text_area.luan").new or error() |
| 9 local new_scroll_pane = require("luan:swing/Scroll_pane.luan").new or error() | 11 local new_scroll_pane = require("luan:swing/Scroll_pane.luan").new or error() |
| 60 | 62 |
| 61 local n_windows = 0 | 63 local n_windows = 0 |
| 62 | 64 |
| 63 function new_window(file) | 65 function new_window(file) |
| 64 local frame = new_frame() | 66 local frame = new_frame() |
| 65 frame.title = file and file.to_string() or "untitled" | 67 frame.title = file and file.canonical().to_string() or "untitled" |
| 66 frame.add_close_listener(function() | 68 frame.add_close_listener(function() |
| 67 n_windows = n_windows - 1 | 69 n_windows = n_windows - 1 |
| 68 if n_windows == 0 then | 70 if n_windows == 0 then |
| 69 Luan.exit() | 71 Luan.exit() |
| 70 end | 72 end |
| 71 end) | 73 end) |
| 72 local text_area = new_text_area() | 74 local text_area = new_text_area() |
| 73 if file ~= nil then | 75 if file ~= nil and file.is_file() then |
| 74 text_area.text = file.read_text() | 76 text_area.text = file.read_text() |
| 75 end | 77 end |
| 76 text_area.rows = 10 | 78 text_area.rows = 10 |
| 77 text_area.columns = 20 | 79 text_area.columns = 20 |
| 78 text_area.wrap_style_word = true | 80 text_area.wrap_style_word = true |
| 100 text_area.request_focus_in_window() | 102 text_area.request_focus_in_window() |
| 101 n_windows = n_windows + 1 | 103 n_windows = n_windows + 1 |
| 102 end | 104 end |
| 103 | 105 |
| 104 Swing.run(function() | 106 Swing.run(function() |
| 105 new_window() | 107 local args = Luan.arg |
| 108 if #args == 0 then | |
| 109 new_window() | |
| 110 else | |
| 111 for _, arg in ipairs(args) do | |
| 112 local file = new_file(arg) | |
| 113 new_window(file) | |
| 114 end | |
| 115 end | |
| 106 end) | 116 end) |
