2013-05-03 10:02:03 +04:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2007-2012, Timothy Stack
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
2022-03-17 01:38:08 +03:00
|
|
|
*
|
2013-05-03 10:02:03 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
2022-03-17 01:38:08 +03:00
|
|
|
*
|
2013-05-03 10:02:03 +04:00
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of Timothy Stack nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2022-03-17 01:38:08 +03:00
|
|
|
*
|
2013-05-03 10:02:03 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
2022-03-17 01:38:08 +03:00
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
2013-05-03 10:02:03 +04:00
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2009-09-14 05:07:32 +04:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <fcntl.h>
|
2020-11-10 09:18:17 +03:00
|
|
|
#include <locale.h>
|
2022-03-17 01:38:08 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2009-09-14 05:07:32 +04:00
|
|
|
|
2020-11-10 09:18:17 +03:00
|
|
|
#include "base/lnav_log.hh"
|
2022-03-17 01:38:08 +03:00
|
|
|
#include "config.h"
|
2009-09-14 05:07:32 +04:00
|
|
|
#include "view_curses.hh"
|
|
|
|
#include "vt52_curses.hh"
|
|
|
|
|
2012-04-19 06:30:53 +04:00
|
|
|
#if defined HAVE_NCURSESW_CURSES_H
|
2022-03-17 01:38:08 +03:00
|
|
|
# include <ncursesw/curses.h>
|
|
|
|
# include <ncursesw/term.h>
|
2012-04-19 06:30:53 +04:00
|
|
|
#elif defined HAVE_NCURSESW_H
|
2022-03-17 01:38:08 +03:00
|
|
|
# include <ncursesw.h>
|
|
|
|
# include <term.h>
|
2012-04-19 06:30:53 +04:00
|
|
|
#elif defined HAVE_NCURSES_CURSES_H
|
2022-03-17 01:38:08 +03:00
|
|
|
# include <ncurses/curses.h>
|
|
|
|
# include <ncurses/term.h>
|
2012-04-19 06:30:53 +04:00
|
|
|
#elif defined HAVE_NCURSES_H
|
2022-03-17 01:38:08 +03:00
|
|
|
# include <ncurses.h>
|
|
|
|
# include <term.h>
|
2012-04-19 06:30:53 +04:00
|
|
|
#elif defined HAVE_CURSES_H
|
2022-03-17 01:38:08 +03:00
|
|
|
# include <curses.h>
|
|
|
|
# include <term.h>
|
2012-04-19 06:30:53 +04:00
|
|
|
#else
|
2022-03-17 01:38:08 +03:00
|
|
|
# error "SysV or X/Open-compatible Curses header file required"
|
2012-04-19 06:30:53 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef set_window
|
|
|
|
|
2022-03-17 01:38:08 +03:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
2009-09-14 05:07:32 +04:00
|
|
|
{
|
2022-03-17 01:38:08 +03:00
|
|
|
int lpc, c, fd, retval = EXIT_SUCCESS;
|
|
|
|
vt52_curses vt;
|
2020-11-10 09:18:17 +03:00
|
|
|
|
2022-03-17 01:38:08 +03:00
|
|
|
setenv("LANG", "en_US.utf-8", 1);
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
fd = open("/tmp/lnav.err", O_WRONLY | O_CREAT | O_APPEND, 0666);
|
|
|
|
dup2(fd, STDERR_FILENO);
|
|
|
|
close(fd);
|
|
|
|
fprintf(stderr, "startup\n");
|
|
|
|
lnav_log_file = stderr;
|
2009-09-14 05:07:32 +04:00
|
|
|
|
2022-03-17 01:38:08 +03:00
|
|
|
while ((c = getopt(argc, argv, "y:")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'y':
|
|
|
|
vt.set_y(atoi(optarg));
|
|
|
|
break;
|
|
|
|
}
|
2009-09-14 05:07:32 +04:00
|
|
|
}
|
|
|
|
|
2022-03-17 01:38:08 +03:00
|
|
|
for (lpc = 0; lpc < 1000; lpc++) {
|
|
|
|
int len;
|
|
|
|
|
|
|
|
assert(vt.map_input(random(), len) != nullptr);
|
|
|
|
assert(len > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
tgetent(nullptr, "vt52");
|
|
|
|
{
|
|
|
|
static const char* CANNED_INPUT[] = {
|
|
|
|
"Gru\xC3\x9F",
|
|
|
|
"\r",
|
|
|
|
tgetstr((char*) "ce", nullptr),
|
|
|
|
"de",
|
|
|
|
"\n",
|
|
|
|
"1",
|
|
|
|
"2",
|
|
|
|
"3",
|
|
|
|
"\n",
|
|
|
|
"abc",
|
|
|
|
"\x02",
|
|
|
|
"\a",
|
|
|
|
"ab\bcdef",
|
|
|
|
};
|
|
|
|
|
|
|
|
screen_curses sc;
|
|
|
|
|
|
|
|
noecho();
|
|
|
|
vt.set_window(sc.get_window());
|
|
|
|
vt.set_width(10);
|
2009-09-14 05:07:32 +04:00
|
|
|
|
2022-03-17 01:38:08 +03:00
|
|
|
for (const auto* canned : CANNED_INPUT) {
|
|
|
|
vt.map_output(canned, strlen(canned));
|
|
|
|
vt.do_update();
|
|
|
|
refresh();
|
|
|
|
view_curses::awaiting_user_input();
|
|
|
|
getch();
|
|
|
|
}
|
2009-09-14 05:07:32 +04:00
|
|
|
|
2022-03-17 01:38:08 +03:00
|
|
|
view_curses::awaiting_user_input();
|
|
|
|
getch();
|
2009-09-14 05:07:32 +04:00
|
|
|
}
|
|
|
|
|
2022-03-17 01:38:08 +03:00
|
|
|
return retval;
|
2009-09-14 05:07:32 +04:00
|
|
|
}
|