forked from enlightenment/edi
115 lines
2.8 KiB
C
115 lines
2.8 KiB
C
|
#ifdef HAVE_CONFIG_H
|
||
|
# include "config.h"
|
||
|
#endif
|
||
|
|
||
|
#define BUFFER_SIZE 1024
|
||
|
|
||
|
#include <Eina.h>
|
||
|
#include <Ecore.h>
|
||
|
|
||
|
#include "edi_consolepanel.h"
|
||
|
|
||
|
#include "edi_private.h"
|
||
|
|
||
|
static Evas_Object *_console_box;
|
||
|
|
||
|
void _edi_consolepanel_append_line_type(const char *line, Eina_Bool err)
|
||
|
{
|
||
|
Evas_Object *txt;
|
||
|
|
||
|
txt = elm_label_add(_console_box);
|
||
|
if (err)
|
||
|
evas_object_color_set(txt, 255, 63, 63, 255);
|
||
|
else
|
||
|
evas_object_color_set(txt, 255, 255, 255, 255);
|
||
|
|
||
|
elm_object_text_set(txt, line);
|
||
|
evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, 0.1);
|
||
|
evas_object_size_hint_align_set(txt, 0.0, EVAS_HINT_FILL);
|
||
|
evas_object_show(txt);
|
||
|
|
||
|
elm_box_pack_end(_console_box, txt);
|
||
|
}
|
||
|
|
||
|
void edi_consolepanel_append_line(const char *line)
|
||
|
{
|
||
|
_edi_consolepanel_append_line_type(line, EINA_FALSE);
|
||
|
}
|
||
|
|
||
|
void edi_consolepanel_append_error_line(const char *line)
|
||
|
{
|
||
|
_edi_consolepanel_append_line_type(line, EINA_TRUE);
|
||
|
}
|
||
|
|
||
|
void edi_consolepanel_clear()
|
||
|
{
|
||
|
elm_box_clear(_console_box);
|
||
|
}
|
||
|
|
||
|
static Eina_Bool _stdin_handler_cb(void *data EINA_UNUSED, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
|
||
|
{
|
||
|
char message[BUFFER_SIZE];
|
||
|
|
||
|
if (!fgets(message, BUFFER_SIZE, stdin))
|
||
|
return ECORE_CALLBACK_RENEW;
|
||
|
|
||
|
edi_consolepanel_append_line(message);
|
||
|
return ECORE_CALLBACK_RENEW;
|
||
|
}
|
||
|
|
||
|
static Eina_Bool _stderr_handler_cb(void *data EINA_UNUSED, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
|
||
|
{
|
||
|
char message[BUFFER_SIZE];
|
||
|
|
||
|
if (!fgets(message, BUFFER_SIZE, stderr))
|
||
|
return ECORE_CALLBACK_RENEW;
|
||
|
|
||
|
edi_consolepanel_append_error_line(message);
|
||
|
return ECORE_CALLBACK_RENEW;
|
||
|
}
|
||
|
|
||
|
static Eina_Bool
|
||
|
exe_data(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Exe_Event_Data *ev)
|
||
|
{
|
||
|
Ecore_Exe_Event_Data_Line *el;
|
||
|
|
||
|
for (el = ev->lines; el && el->line; el++)
|
||
|
edi_consolepanel_append_line(el->line);
|
||
|
|
||
|
return ECORE_CALLBACK_RENEW;
|
||
|
}
|
||
|
|
||
|
static Eina_Bool
|
||
|
exe_error(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Exe_Event_Data *ev)
|
||
|
{
|
||
|
Ecore_Exe_Event_Data_Line *el;
|
||
|
|
||
|
for (el = ev->lines; el && el->line; el++)
|
||
|
edi_consolepanel_append_error_line(el->line);
|
||
|
|
||
|
return ECORE_CALLBACK_RENEW;
|
||
|
}
|
||
|
|
||
|
void edi_consolepanel_add(Evas_Object *parent)
|
||
|
{
|
||
|
Evas_Object *scroll, *vbx;
|
||
|
|
||
|
scroll = elm_scroller_add(parent);
|
||
|
elm_scroller_gravity_set(scroll, 0.0, 0.0);
|
||
|
evas_object_size_hint_weight_set(scroll, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||
|
evas_object_size_hint_align_set(scroll, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||
|
evas_object_show(scroll);
|
||
|
|
||
|
vbx = elm_box_add(parent);
|
||
|
evas_object_size_hint_weight_set(vbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||
|
evas_object_show(vbx);
|
||
|
elm_object_content_set(scroll, vbx);
|
||
|
|
||
|
_console_box = vbx;
|
||
|
|
||
|
elm_object_content_set(parent, scroll);
|
||
|
|
||
|
ecore_event_handler_add(ECORE_EXE_EVENT_DATA, exe_data, NULL);
|
||
|
ecore_event_handler_add(ECORE_EXE_EVENT_ERROR, exe_error, NULL);
|
||
|
}
|