From 63559385e7861658e8e9a907636519f18fe74c0e Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Fri, 5 Nov 2021 00:17:50 -0400 Subject: [PATCH 1/8] base lua tui window --- tui.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tui.lua diff --git a/tui.lua b/tui.lua new file mode 100644 index 0000000..f2b932f --- /dev/null +++ b/tui.lua @@ -0,0 +1,14 @@ +local ltui = require("ltui") +local application = ltui.application +local event = ltui.event +local rect = ltui.rect +local window = ltui.window +local demo = application() + +function demo:init() + application.init(self, "demo") + self:background_set("blue") + self:insert(window:new("window.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main window", true)) +end + +demo:run() -- 2.49.0 From eea5ee0e3f8cef627492b8043462d67e800ad69c Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Fri, 5 Nov 2021 01:04:53 -0400 Subject: [PATCH 2/8] changed ui to a dialog --- tui.lua | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tui.lua b/tui.lua index f2b932f..7a80b6c 100644 --- a/tui.lua +++ b/tui.lua @@ -1,14 +1,47 @@ +-- requires local ltui = require("ltui") +local label = ltui.label +local button = ltui.button local application = ltui.application local event = ltui.event local rect = ltui.rect -local window = ltui.window -local demo = application() +local inputdialog = ltui.inputdialog +-- the demo application +local demo = application() + +-- init demo function demo:init() + + -- init name application.init(self, "demo") + + -- init background self:background_set("blue") - self:insert(window:new("window.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main window", true)) + + -- init input dialog + self:insert(self:dialog_input(), {centerx = true, centery = true}) end +-- input dialog +function demo:dialog_input() + local dialog_input = self._DIALOG_INPUT + if not dialog_input then + dialog_input = inputdialog:new("dialog.input", rect{0, 0, math.floor(self:width() / 2), math.floor(self:height() / 3)}) + dialog_input:text():text_set("please input text:") + dialog_input:button_add("no", "< No >", function (v) dialog_input:quit() end) + dialog_input:button_add("yes", "< Yes >", function (v) dialog_input:quit() end) + self._DIALOG_INPUT = dialog_input + end + return dialog_input +end + +-- on resize +function demo:on_resize() + self:dialog_input():bounds_set(rect{0, 0, math.floor(self:width() / 2), math.floor(self:height() / 3)}) + self:center(self:dialog_input(), {centerx = true, centery = true}) + application.on_resize(self) +end + +-- run demo demo:run() -- 2.49.0 From dc49dbf65b6ec0c13166d7358055c8b76aa634ed Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Fri, 5 Nov 2021 01:05:18 -0400 Subject: [PATCH 3/8] changed ui to a dialog --- tui.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tui.lua b/tui.lua index 7a80b6c..e339656 100644 --- a/tui.lua +++ b/tui.lua @@ -1,3 +1,28 @@ +--!A cross-platform terminal ui library based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file inputdialog.lua +-- +-- require("tests/load") + -- requires local ltui = require("ltui") local label = ltui.label -- 2.49.0 From 6de5afde596633dd8fc5cac16f40314bc00f55c4 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Fri, 5 Nov 2021 13:48:55 -0400 Subject: [PATCH 4/8] accept command line args --- quadratic.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/quadratic.c b/quadratic.c index 00c05c2..5d53d77 100644 --- a/quadratic.c +++ b/quadratic.c @@ -2,7 +2,7 @@ #include #include -int main() +int main(int num_arg, char** args) { system("clear"); printf("\n ~~ Quadratic Calculator ~~\n"); @@ -10,6 +10,12 @@ int main() printf(" ̲-̲b̲±̲√̲b̲̲²̲̲-̲4̲a̲c̲\n"); printf(" 2a\n\n"); + printf("there are %d arguments\n", num_arg); + + for(int i=0; i < num_arg; ++i){ + printf("%s\n", args[i]); + }; + double num_A, num_B, num_C; printf("Please enter the value for \"a\":\n"); -- 2.49.0 From 51a1738e1838c4cd920e0f577172da414c4c290c Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Fri, 5 Nov 2021 17:02:17 -0400 Subject: [PATCH 5/8] commandline parameters support --- quadratic.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/quadratic.c b/quadratic.c index 5d53d77..95c3cda 100644 --- a/quadratic.c +++ b/quadratic.c @@ -1,53 +1,54 @@ #include #include #include +#include -int main(int num_arg, char** args) +int main(int num_arg, char **args) { - system("clear"); - printf("\n ~~ Quadratic Calculator ~~\n"); - printf(" ̲ ̲ ̲ ̲ ̲ ̲\n"); - printf(" ̲-̲b̲±̲√̲b̲̲²̲̲-̲4̲a̲c̲\n"); - printf(" 2a\n\n"); - - printf("there are %d arguments\n", num_arg); - - for(int i=0; i < num_arg; ++i){ - printf("%s\n", args[i]); - }; - double num_A, num_B, num_C; - printf("Please enter the value for \"a\":\n"); - scanf("%lf", &num_A); - printf("Please enter the value for \"b\":\n"); - scanf("%lf", &num_B); - printf("Please enter the value for \"c\":\n"); - scanf("%lf", &num_C); + if (num_arg <= 1) + { + system("clear"); + printf("\n ~~ Quadratic Calculator ~~\n"); + printf(" ̲ ̲ ̲ ̲ ̲ ̲\n"); + printf(" ̲-̲b̲±̲√̲b̲̲²̲̲-̲4̲a̲c̲\n"); + printf(" 2a\n\n"); + + printf("Please enter the value for \"a\":\n"); + scanf("%lf", &num_A); + printf("Please enter the value for \"b\":\n"); + scanf("%lf", &num_B); + printf("Please enter the value for \"c\":\n"); + scanf("%lf", &num_C); + printf("\n"); + } + else + { + num_A = atof(args[1]); + num_B = atof(args[2]); + num_C = atof(args[3]); + }; double radical = pow(num_B, 2) + (-4 * num_A * num_C); - printf("\nUnder the radical: %f\n", radical); + if (radical < 0.0) { // roots are complex - printf("Roots are complex.\n"); - double real_part = (-num_B) / (2 * num_A); double imaginary_part = sqrt(radical * -1.0) / (2 * num_A); - printf("The zeros are: %f+%fi and %f-%fi.\n", real_part, imaginary_part, real_part, imaginary_part); + printf("%f+%fi %f-%fi\n", real_part, imaginary_part, real_part, imaginary_part); } else { // roots are real - printf("Roots are real.\n"); - double numerator_1 = (-num_B) + sqrt(radical); double numerator_2 = (-num_B) - sqrt(radical); double zero_1_ptr = numerator_1 / (2 * num_A); double zero_2_ptr = numerator_2 / (2 * num_A); - printf("The zeros are: %f and %f.\n", zero_1_ptr, zero_2_ptr); + printf("%f %f\n", zero_1_ptr, zero_2_ptr); }; return 0; }; -- 2.49.0 From 533eb5243e12c96d36e902dfb35b7e43470aadf3 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Fri, 5 Nov 2021 17:08:47 -0400 Subject: [PATCH 6/8] not going to use LTUI --- tui.lua | 72 --------------------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 tui.lua diff --git a/tui.lua b/tui.lua deleted file mode 100644 index e339656..0000000 --- a/tui.lua +++ /dev/null @@ -1,72 +0,0 @@ ---!A cross-platform terminal ui library based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file inputdialog.lua --- --- require("tests/load") - --- requires -local ltui = require("ltui") -local label = ltui.label -local button = ltui.button -local application = ltui.application -local event = ltui.event -local rect = ltui.rect -local inputdialog = ltui.inputdialog - --- the demo application -local demo = application() - --- init demo -function demo:init() - - -- init name - application.init(self, "demo") - - -- init background - self:background_set("blue") - - -- init input dialog - self:insert(self:dialog_input(), {centerx = true, centery = true}) -end - --- input dialog -function demo:dialog_input() - local dialog_input = self._DIALOG_INPUT - if not dialog_input then - dialog_input = inputdialog:new("dialog.input", rect{0, 0, math.floor(self:width() / 2), math.floor(self:height() / 3)}) - dialog_input:text():text_set("please input text:") - dialog_input:button_add("no", "< No >", function (v) dialog_input:quit() end) - dialog_input:button_add("yes", "< Yes >", function (v) dialog_input:quit() end) - self._DIALOG_INPUT = dialog_input - end - return dialog_input -end - --- on resize -function demo:on_resize() - self:dialog_input():bounds_set(rect{0, 0, math.floor(self:width() / 2), math.floor(self:height() / 3)}) - self:center(self:dialog_input(), {centerx = true, centery = true}) - application.on_resize(self) -end - --- run demo -demo:run() -- 2.49.0 From e90ab33dd8db262391c6c5a6ff209f494b89e476 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Fri, 5 Nov 2021 17:54:18 -0400 Subject: [PATCH 7/8] tui bash prompt --- tui.bash | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tui.bash diff --git a/tui.bash b/tui.bash new file mode 100755 index 0000000..64b8b4a --- /dev/null +++ b/tui.bash @@ -0,0 +1,26 @@ +ARG_A=$(whiptail --inputbox "Please enter the value for \"a\":" 10 50 --title "Quadratic Calculator" 3>&1 1>&2 2>&3) + +exitstatus=$? +if [ $exitstatus = 0 ]; then +echo "a =" $ARG_A +else +echo "User canceled input." +fi + +ARG_B=$(whiptail --inputbox "Please enter the value for \"b\":" 10 50 --title "Quadratic Calculator" 3>&1 1>&2 2>&3) + +exitstatus=$? +if [ $exitstatus = 0 ]; then +echo "b =" $ARG_B +else +echo "User canceled input." +fi + +ARG_C=$(whiptail --inputbox "Please enter the value for \"C\":" 10 50 --title "Quadratic Calculator" 3>&1 1>&2 2>&3) + +exitstatus=$? +if [ $exitstatus = 0 ]; then +echo "c =" $ARG_C +else +echo "User canceled input." +fi -- 2.49.0 From 352f3a9472ba1215b75b8ff2b4d5f2a7aecac440 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Fri, 5 Nov 2021 18:01:13 -0400 Subject: [PATCH 8/8] tui completed --- tui.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tui.bash b/tui.bash index 64b8b4a..e71e96a 100755 --- a/tui.bash +++ b/tui.bash @@ -24,3 +24,5 @@ echo "c =" $ARG_C else echo "User canceled input." fi + +quadratic $ARG_A $ARG_B $ARG_C \ No newline at end of file -- 2.49.0