Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) PdcursesExample3

 

STLQt CreatorWindows

 

PDCurses example 3: text editor is a PDCurses example that tries to behave a bit like a text editor.

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppPdcursesExample3/CppPdcursesExample3.pro

 

include(../../ConsoleApplication.pri) #Or use the code below
# QT += core
# QT += gui
# greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
# CONFIG   += console
# CONFIG   -= app_bundle
# TEMPLATE = app
# CONFIG(release, debug|release) {
#   DEFINES += NDEBUG NTRACE_BILDERBIKKEL
# }
# QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++
# unix {
#   QMAKE_CXXFLAGS += -Werror
# }

include(../../Libraries/Boost.pri) #Or use the code below
# win32 {
#   INCLUDEPATH += \
#     ../../Libraries/boost_1_54_0
# }

include(../../Libraries/Pdcurses.pri) #Or use the code below
# win32 {
#   INCLUDEPATH += \
#       ../../Libraries/pdc25_vc_w32
#
#   HEADERS += \
#       ../../Libraries/pdc25_vc_w32/panel.h \
#       ../../Libraries/pdc25_vc_w32/curses.h
#
#   LIBS += -L../../Libraries/pdc25_vc_w32 -lpdcurses
# }

SOURCES += main.cpp

 

 

 

 

 

./CppPdcursesExample3/main.cpp

 

#include <cassert>
#include <cstdlib>
#include <csignal>
#include <iostream>
#include "curses.h"

static void finish(int sig);

int main()
{
  std::signal(SIGINT, finish);
  initscr();
  keypad(stdscr, TRUE);
  cbreak();

  int x = 0;
  int y = 0;

  while (1)
  {
    move(y,x);
    refresh();
    const int c = getch();
    switch (c)
    {
      case KEY_SHIFT_L:
      case KEY_SHIFT_R:
      case KEY_CONTROL_L:
      case KEY_CONTROL_R:
      case KEY_ALT_L:
      case KEY_ALT_R:
        break;
      case KEY_UP   : y-=(y-1>   0  ? 1 : 0); break;
      case KEY_RIGHT: x+=(x+1<COLS  ? 1 : 0); break;
      case KEY_DOWN : y+=(y+1<LINES ? 1 : 0); break;
      case KEY_LEFT : x-=(x-1>   0  ? 1 : 0); break;
      case 8: case KEY_BACKSPACE: x-=(x-1>0 ? 1 : 0); move(y,x); addch(' '); break;
      case KEY_EXIT: finish(0);
      default: addch(c); x+=(x+1<COLS  ? 1 : 0); break;
    }
  }
  finish(0);
}

static void finish(int sig)
{
  endwin();
  std::exit(sig);
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml