1
1
mirror of https://github.com/tstack/lnav.git synced 2024-08-16 08:20:29 +03:00
lnav/test/drive_vt52_curses.cc

134 lines
3.8 KiB
C++
Raw Normal View History

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>
#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
2024-04-29 16:38:29 +03:00
#include "base/injector.bind.hh"
#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"
2024-04-29 16:38:29 +03:00
#include "xterm_mouse.hh"
2009-09-14 05:07:32 +04:00
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
2024-04-29 16:38:29 +03:00
static auto bound_xterm_mouse = injector::bind<xterm_mouse>::to_singleton();
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;
setenv("LANG", "en_US.UTF-8", 1);
2022-03-17 01:38:08 +03:00
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",
};
2022-08-22 23:15:31 +03:00
auto sc = screen_curses::create().unwrap();
2022-03-17 01:38:08 +03:00
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
}