Commit b1407b4e authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Bind the fake console

parent 917ee891
Pipeline #97274 passed with stages
in 6 minutes and 10 seconds
......@@ -20,6 +20,7 @@ rm -rf ../tarot-*.tar.gz ../tarot-*/ tarot-*.tar.gz
sh autogen.sh || exit 1
./configure \
CFLAGS="-Wall -Wextra -Werror -g -O0 $CFLAGS" \
VALAFLAGS="--target-glib=2.50" \
--prefix="$SOURCE_TOP/public" \
--enable-valgrind=yes \
|| (cat config.log ; exit 1) \
......@@ -28,7 +29,7 @@ make indent || exit 1
(cd lib-library && make -j 16) || exit 1
(cd lib-program && make -j 16) || exit 1
# I don't know exactly which targets are not thread safe...
make VALAFLAGS="--target-glib=2.50" dist || exit 1
make dist || exit 1
make -j 16 distcheck \
|| (cat "$SOURCE_TOP/tarot-$(cat .version)/_build/sub/test-suite.log" ; exit 1) \
|| exit 1
......
......@@ -41,6 +41,7 @@ AM_MISSING_PROG([CONVERT], [convert])
GOBJECT_INTROSPECTION_CHECK([1.30.0])
PKG_CHECK_VAR([GLIB_MKENUMS], [glib-2.0], [glib_mkenums])
AM_PROG_VALAC
AC_ARG_VAR([VALAFLAGS], [Additional flags to pass to the vala compiler])
VAPIGEN_CHECK
AM_MISSING_PROG([GLIB_COMPILE_RESOURCES], [glib-compile-resources])
......@@ -85,6 +86,12 @@ AS_IF([test "x$with_gtk" != "xno"], [
])
])
AM_CONDITIONAL([WITH_GTK], [test "x$WITH_GTK" != "xno"])
HAVE_GTK=0
AS_IF([test "x$WITH_GTK" != "xno"], [
AC_DEFINE([HAVE_GTK], [1], [Whether we have the Gtk+ bindings])
], [
AC_DEFINE([HAVE_GTK], [0], [Whether we have the Gtk+ bindings])
])
AC_SEARCH_LIBS([atan2], [m])
AC_SEARCH_LIBS([sin], [m])
AC_SEARCH_LIBS([cos], [m])
......
This diff is collapsed.
......@@ -69,9 +69,7 @@ dist_man_MANS += %reldir%/tarot.6
%canon_reldir%_tarot_SOURCES = \
%reldir%/main.c \
%reldir%/tarot-opts.c \
%reldir%/tarot-opts.h \
%reldir%/application.vala \
%reldir%/tarot-1.0.vapi
%reldir%/tarot-opts.h
%canon_reldir%_tarot_CFLAGS = \
$(AM_CFLAGS) \
$(LIBOPTS_CFLAGS) \
......
......@@ -34,6 +34,9 @@ extern "C"
struct TarotCli;
typedef struct TarotCli TarotCli;
/**
* tarot_cli_alloc: (constructor):
*/
TarotCli *tarot_cli_alloc ();
/**
......@@ -50,6 +53,10 @@ extern "C"
*/
TarotCli *tarot_cli_dup (const TarotCli * cli);
/**
* tarot_cli_push:
* @eof: (type boolean):
*/
int tarot_cli_push (TarotCli * cli, const char *data, int eof);
int tarot_cli_next (TarotCli * cli);
......
......@@ -36,7 +36,12 @@ EXTRA_DIST += \
if WITH_GTK
%canon_reldir%_libtarot_application_gui_la_SOURCES = \
%reldir%/tarot_application_with_gui.vala \
%reldir%/engine.c \
%reldir%/tarot_application_without_gui.c
if WITH_GOBJECT
src_tarot_SOURCES += \
%reldir%/tarot-resources.c
endif # WITH_GOBJECT
%canon_reldir%_libtarot_application_gui_la_CFLAGS = \
$(AM_CFLAGS) \
$(GTK_CFLAGS) \
......@@ -45,10 +50,11 @@ if WITH_GTK
%canon_reldir%_libtarot_application_gui_la_LIBS = \
$(AM_LIBS) \
$(GTK_LIBS)
AM_CPPFLAGS += -Dtarot_gui_try_run=tarot_gui_try_run_with_gui
else # not WITH_GTK
%canon_reldir%_libtarot_application_gui_la_SOURCES = \
%reldir%/tarot_application_without_gui.vala
%reldir%/tarot_application_without_gui.vala \
%reldir%/engine.vala \
src/tarot-1.0.vapi
%canon_reldir%_libtarot_application_gui_la_CFLAGS = \
$(AM_CFLAGS) \
$(GOBJECT_CFLAGS) \
......@@ -57,5 +63,4 @@ else # not WITH_GTK
%canon_reldir%_libtarot_application_gui_la_LIBS = \
$(GOBJECT_LIBS) \
$(AM_LIBS)
AM_CPPFLAGS += -Dtarot_gui_try_run=tarot_gui_try_run_without_gui
endif # not WITH_GTK
......@@ -25,19 +25,47 @@
<child>
<object class="GtkTextView" id="console">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_focus">False</property>
<property name="editable">False</property>
<property name="monospace">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="input">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="input">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="is_focus">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="send">
<property name="label" translatable="yes">Send</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="send_clicked_cb" swapped="no"/>
<accelerator key="m" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
......@@ -56,4 +84,4 @@
</object>
</child>
</template>
</interface>
\ No newline at end of file
</interface>
......@@ -19,12 +19,46 @@
namespace Tarot {
[GtkTemplate (ui = "/eu/planete_kraus/Tarot/main_window.ui")]
public class Window: Gtk.ApplicationWindow {
private Tarot.Engine engine = new Tarot.Engine ();
private Tarot.Cli cli = new Tarot.Cli.alloc ();
[GtkChild]
private Gtk.TextView console;
[GtkChild]
private Gtk.Entry input;
[GtkCallback]
private void send_clicked_cb () {
console.buffer.text = "";
string line = input.text;
input.text = "";
if (line != "") {
if (cli.push (line, false) != 0) {
GLib.Process.abort ();
}
while (cli.has_command ()) {
if (engine.command (ref cli)) {
close ();
}
cli.next ();
}
}
}
public Window (Gtk.Application app) {
Object (application: app);
engine.print.connect ((str) => {
console.buffer.text += str;
});
engine.print_error.connect ((str) => {
console.buffer.text += "!! {" + str + "}";
});
engine.print_user_greeting ();
}
}
namespace Gui {
public static bool try_run_with_gui (bool brief, out int exit_status) {
public static int try_run_with_gui (bool brief) {
var app = new Gtk.Application ("eu.planete_kraus.Tarot", ApplicationFlags.FLAGS_NONE);
app.activate.connect (() => {
var window = app.active_window;
......@@ -34,9 +68,7 @@ namespace Tarot {
}
window.present ();
});
var return_value = app.run (null);
exit_status = return_value;
return false;
return app.run (null);
}
}
}
\ No newline at end of file
// file tarot_application.vala
// file tarot_application_without_gui.vala
//
// Copyright (C) 2017, 2018 Vivien Kraus <vivien@planete-kraus.eu>
//
......@@ -16,11 +16,48 @@
// along with this program. If not, see
// <http://www.gnu.org/licenses/>.
extern string? readline (string prompt);
extern void add_history (string command);
namespace Tarot {
namespace Gui {
public static bool try_run_without_gui (bool brief, out int exit_status) {
exit_status = 0;
return true;
public static int try_run_without_gui (bool brief) {
string? new_line = null;
var cli = new Tarot.Cli.alloc ();
bool done = false;
var app = new Tarot.Engine ();
app.print.connect ((str) => { stdout.printf ("%s", str); });
app.print_error.connect ((str) => { stderr.printf ("%s", str); });
if (!brief) {
app.print_user_greeting ();
}
while (!done) {
string prompt_primary = "> ";
string prompt_secondary = ". ";
string prompt = prompt_primary;
if (cli.is_continuation ()) {
prompt = prompt_secondary;
}
new_line = readline (prompt);
if (new_line == null) {
if (cli.push ("", true) != 0) {
GLib.Process.abort ();
}
done = true;
} else if (new_line != "") {
if (cli.push (new_line, false) != 0) {
GLib.Process.abort ();
}
add_history (new_line);
}
while (cli.has_command ()) {
if (app.command (ref cli)) {
done = true;
}
cli.next ();
}
}
return 0;
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment