LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Blogs > rainbowsally
User Name
Password

Notices

Rate this Entry

mini-term in qt4

Posted 01-17-2013 at 03:34 AM by rainbowsally
Updated 08-06-2014 at 07:58 AM by rainbowsally

mini-term in qt4.

Today's features:
  • A simple terminal-like application built from a qt4 class that can be used for other stuff too.
  • The present application can run shell commands and has copy/paste (ctrl-c, ctrl-v) capabilitity.
  • Another example of the Windows-like api so that C/C++ code can run in Qt4.
  • Runs the custom code (terminal in this case) inside a QT 'exec' loop... sorta. We call it 'run()'.

Screenshot:
http://rainbowsally.org/rainbowsally...iterm-test.png

If you want to try this, be forewarned:
Run
Code:
make ui
and then
Code:
make
So that all the moc_&.cpp files are created before you 'make' the app itself.

[I won't go into depth on the api thing, but with four parameters Windows gives strong clues as to typing without enforcing overly-strict typing rules. And integer will go into wparam. A pointer or a struct will go into lparam. Messages identify it more completely and tell what to do with it. It's intuitive by nature and one of the few features of Windows that I like better than any linux gui toolkits I've tried so far.]

The self extractor (near the bottom) contains all the files including the Makefile and the mc2.def that created the Makefile but let's take look at the api, which is the layer between our custom code and the Designer-generated gui code.

file: miniterm-test/app-main.cpp
purpose: source file
Code:
#include <QtGui/QApplication>
#include "lqminiterm.h"
#include "ui_lqminiterm.h"
#include <ctype.h> // alnum()
#include <stdio.h>

void dbg(){}

static bool cmd_set;
static char* cmd;
static bool text_mode;

static void term_print(lqMiniTerm* term, const char* buf)
{
  text_mode = true;
  term->ui->plainTextEdit->appendPlainText(buf);
  text_mode = false;
  term->ui->plainTextEdit->textCursor().movePosition(QTextCursor::End);
  term->last_pos = 
      term->ui->plainTextEdit->textCursor().position();

}

static void prompt(lqMiniTerm* term)
{
  char buf[256];
  sprintf(buf, "%s", getenv("PWD"));
  int pathlen = strlen(buf);
  // trim path down to 40 chars
  if(pathlen > 40)
    sprintf(buf + 18, "...%s", buf + pathlen - 19);
  
  strcat(buf, "$>");
  term_print(term, buf);
}

// user programmable loop func in app-main()
// this just does shell commands.
void loop_func(lqMiniTerm* term)
{
  // only operates in command mode
  if(text_mode)
    return;
  
  char* cmdptr = cmd;
  int slen;
  
  if(!cmd_set)
    return;
  
  cmd_set = false;

  // queue up text
  while(isspace(*cmdptr))
    cmdptr++;
  
  if(!*cmdptr)
    return;
  
  
  ////////////////////////////////////////////
  // A couple of keywords we handle ourselves
  // 'cd' <path> | 'exit'
  
  char firstword[256];
  sscanf(cmdptr, "%s", firstword);
  
  if(strcmp(firstword, "cd") == 0)
  {
    cmdptr += 3;
    while(isspace(*cmdptr))
      cmdptr++;
        
    char* cwd;
    chdir(cmdptr);
    cwd = getcwd(0, 0);
    setenv("PWD", cwd, true);
    free(cwd);
    prompt(term);
    return;
  }
  else 
    if(strcmp(firstword, "exit") == 0)
    {
      term->onClose();
    }
  
  ////////////////////////////////////////
  // piped shell command
  char* buf = (char*)malloc(256);
  size_t bufsize = 256;
  sprintf(buf, "%s 2>&1", cmdptr);
  FILE* p = popen(buf, "r");
  while(!feof(p))
  {
    *buf = 0;
    getline(&buf, &bufsize, p);
    slen = strlen(buf);
    if(!slen)
      break;
    buf[slen-1] = 0;
    term_print(term, buf);
  }
  fclose(p);
  free(buf);
  prompt(term);
}


#define UNUSED(x) x=x
void handler(lqMiniTerm* hwnd, uint msg, long wparam, void* lparam)
{
  UNUSED(lparam);
  switch(msg)
  {
    case msg_init:
      text_mode = false;
      break;
    case msg_onClose:
      // printf("Handled: Closing\n");
      hwnd->hide(); // signal to runner we can quit
      hwnd->close();
      break;
    case msg_onNewline:
    {
      // to get the newly entered text we take the text edit's buffer
      // from last_pos to cur_pos and update last_pos in the class
      int last_pos = hwnd->last_pos;
      int cur_pos = hwnd->ui->plainTextEdit->textCursor().position();
      if(!text_mode && (cur_pos >= last_pos))
      {
        QString str = hwnd->ui->plainTextEdit->document()->toPlainText();
        const char* s = str.right(cur_pos - last_pos);
        int len = strlen(s);
        if(len && !cmd_set)
        {
          cmd = (char*)realloc(cmd, len);
          memcpy(cmd, s, len);
          cmd[len-1] = 0;
          cmd_set = true;
          printf("Text: %s\n", cmd);
        }
      }
      // and... only if cur_pos > last_pos
      hwnd->last_pos = cur_pos;
      // printf("Handled: Newline, block = %d\n", (int)wparam);
      break;
    }
    case msg_onCursorPositionChanged:
    {
      // printf("Handled: Cursor Position: pos=%d\n",(int)wparam);
      int new_pos = (int)wparam;
      if(new_pos < hwnd->last_pos)
        hwnd->ui->plainTextEdit->setReadOnly(true);
      else
        hwnd->ui->plainTextEdit->setReadOnly(false);
      break;
    }
  }
}

int main(int argc, char *argv[])
{
  dbg();
  
  // this sets the global qApp instance
  new QApplication (argc, argv);
  
  lqMiniTerm w(loop_func, handler);
  w.show();
  prompt(&w);

  // return qApp->exec();
  return w.run();
}
Take a look at the definition of
Code:
void handler(lqMiniTerm* hwnd, uint msg, long wparam, void* lparam)
in the source above.

The enums are identical to the 'slot' names plus a prefix of 'msg_'.

These slots are never polymorphic, so this is a reliable system for identifying calls and their parameters.

Here are some snips from the header.
Code:
enum{
  msg_init = 0,               // 0 (obj,0,0,0)
  msg_onClose,                // 1 (obj,1,0,0)
  msg_onNewline,              // 2 (obj,2,0,0)
  msg_onCursorPositionChanged // 3 (obj,3,int,0)
};
There's the enums (above). And here's the class functions from the cpp file (below) and you'll notice that the call types are all the same and the resemblance to the Windows WNDPROC is no accident.

Code:
void lqMiniTerm::onClose()
{
  handler(this, msg_onClose, 0, 0);
}

void lqMiniTerm::onNewline(int argA)
{
  handler(this, msg_onNewline, argA, 0);  
}

void lqMiniTerm::onCursorPositionChanged()
{
  QTextCursor cursor = ui->plainTextEdit->textCursor();
  int pos = cursor.position();  
  handler(this, msg_onCursorPositionChanged, pos, 0);
}

void lqMiniTerm::init()
{
  handler(this, msg_init, 0, 0);
}
All these 'slots' do is translate from QT slots to generic calls to handler(). As you can see it would be pretty difficult to pass the wrong type of parameter in the wrong parameter position.

Another interesting feature in the app-main.cpp file (i.e. coded independently from the ui code) is its definition of
Code:
void loop_func(lqMiniTerm* term)
That code runs every 20 milliseconds by default, but can be set to run slower or faster, either at setup time or when you need the speed.

It's not a message loop. It's better in some ways due to its simplicity.

This code, the application, and the interface to the ui can be used to do software "breadboarding".

Doncha just HATE those sockets tutorials where you have to open two terminals to run the things?

Sockets code can run in these loops. No second thread, no mutex, no timing issues. And no dependency on QT threads, so I'm thinking this will be great for really understanding sockets... when I get those done.

The key to this mutability is in the code here.
Code:
// return qApp->exec();
return w.run();
where 'run()' is defined as follows.

Code:
int lqMiniTerm::run()
{
  for(;;)
  {
    qApp->processEvents();
    if(!isVisible())
      break;
    loopFunc(this);
    usleep(loop_timeout * 1000);
  }
  return 0;
}
And that loopFunc is the same loop_func() in the app-main source above. It's the function that curretnly is designed reads input from the text edit widget and decides how to execute it.

Interested? Here's the self extractor.

file: miniterm-test.sfxz
purpose: utility (executable)
Code:
#!/bin/sh
# base64 self extractor
# file: miniterm-test

filename=miniterm-test

# don't allow user to click on the file
if ! tty >/dev/null; then
  xmessage -center "
  $(basename $0)
  must be run in a terminal 
  "
  exit
fi

# create and/or clear out tmp dir
mkdir -p $HOME/tmp/sfxz
rm -rf $HOME/tmp/sfxz/*
base64 -d << _BEOF >$HOME/tmp/sfxz/$filename.xz
/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4Hf/E4VdABcLyicp/zwdmtDjvhk02Zlm07MjuNGYcuId
/xrcMqa+c2gn6syH0xPRjsH/34EHYnDky2YVUiTRI5oJo/UW6xdtMv8l0tSI8kRkXX3r8uDeCXvW
SdqPwq9MhtC/mepY6wpxSm5CpGD7JTwxMEs1A6g24N37JLsX+9phCjdLlgYh8h4czn0Ax3phdD9A
bFm+Pd8EVCjl5rbfW8mhi5qYtbhPVqefyd6Ei6I3YV00DEDepFG+gZ3P3EiLWKm+Zvo7826JTJbX
H9Bw6Ct6NvOu1e9jDMkRakzIBl0czOEp7aCvr2FOfAJvZpP4wyohNIiC0mns758g3kLfzJXMndXe
eO+eCtLnrfv7JS/EI4MhgT3p7D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/sfxz && tar -xaf miniterm-test.xz)
rm -f $HOME/tmp/sfxz/miniterm-test.xz
 
cat << _BEOF > $HOME/tmp/sfxz/post-extract
#!/bin/sh

is_yes() # returns OK if first char is Y or y
{
  local key=`echo $1 | cut -b1 | sed 's/y/Y/; /Y/!d'`
  [ "$key" == 'Y' ] && return 0 # true
  return 1 # false
}

if [ -e miniterm-test ]; then
  printf "
  Overwrite existing file(s)? [N/y]:"
  read key
  if ! is_yes $key ;then
  echo "Aborting.."
    exit 0
  fi
fi

mv $HOME/tmp/sfxz/miniterm-test .
_BEOF

sh $HOME/tmp/sfxz/post-extract
rm -rf $HOME/tmp/sfxz/*
rmdir $HOME/tmp/sfxz 2>/dev/null || true
rmdir $HOME/tmp 2>/dev/null || true
Once again, be aware that you have to 'make ui' before you 'make' the application. That's how we keep the sizes reasonable.

Good luck!

PS. If you click on the app it opens in the default directory. And there appears to be some confusion about what that is! PWD says your home dir. Qt or KDE says it's Documents. "cd .." to get to your REAL home dir or add code to make it open where it was clicked on or something.

If you have libLQ and mc2, type 'lq-find appdir' if you want to see some code for opening it in the folder where it was clicked on. (uses getpid() and readlink())

The Computer Mad Science Team

:-)
Posted in Uncategorized
Views 463 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 07:00 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration