Skip to content
Snippets Groups Projects
Commit 2fde0482 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

started with command line interface

parent 0309f6c0
No related branches found
No related tags found
No related merge requests found
......@@ -35,9 +35,37 @@ set(CMAKE_AUTOUIC ON)
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Build parser
find_package(Flex REQUIRED)
find_package(Bison 3.0 REQUIRED)
# temp dir for parser
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/parser)
# parser
BISON_TARGET(cliparser tools/cli/cliparser.y ${CMAKE_CURRENT_BINARY_DIR}/parser/cliparser_impl.cpp
COMPILE_FLAGS "-S lalr1.cc --defines=${CMAKE_CURRENT_BINARY_DIR}/parser/cliparser_impl.h")
# lexer
FLEX_TARGET(clilexer tools/cli/clilexer.l ${CMAKE_CURRENT_BINARY_DIR}/parser/clilexer_impl.cpp
COMPILE_FLAGS "--c++ --header-file=${CMAKE_CURRENT_BINARY_DIR}/parser/clilexer_impl.h")
ADD_FLEX_BISON_DEPENDENCY(clilexer cliparser)
# let moc ignore the generated files
set_property(SOURCE
parser/cliparser_impl.cpp parser/cliparser_impl.h parser/cliparser_impl.hpp
parser/clilexer_impl.cpp parser/clilexer_impl.h parser/clilexer_impl.hpp
PROPERTY SKIP_AUTOGEN ON)
# -----------------------------------------------------------------------------
include_directories(
"${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/ext"
"${Boost_INCLUDE_DIRS}" "${Boost_INCLUDE_DIRS}/.."
"${PROJECT_SOURCE_DIR}/tools/cli" "${PROJECT_BINARY_DIR}/parser"
)
......@@ -45,6 +73,11 @@ add_executable(in20
tools/in20/main.cpp tools/in20/mainwnd.cpp tools/in20/mainwnd.h
tools/in20/filebrowser.cpp tools/in20/filebrowser.h
tools/in20/workspace.cpp tools/in20/workspace.h
tools/in20/command.cpp tools/in20/command.h
${BISON_cliparser_OUTPUT_SOURCE} ${BISON_cliparser_OUTPUT_HEADER}
${FLEX_clilexer_OUTPUTS} ${FLEX_clilexer_OUTPUT_HEADER}
tools/cli/cliparser.cpp tools/cli/cliparser.h tools/cli/cliparser_types.h
ext/tlibs/log/log.cpp ext/tlibs/file/loadinstr.cpp
......
......@@ -13,10 +13,6 @@
#include "cliparser.h"
%}
/*
integer [+-]?[0-9]+
real [+-]?(([0-9]+\.?[0-9]*)|(\.[0-9]+))
*/
integer [0-9]+
real (([0-9]+\.?[0-9]*)|(\.[0-9]+))
......
......@@ -132,9 +132,11 @@ void CliASTCall::Print(int indent) const
/*
int main()
{
CliParserContext ctx;
yy::CliParser parser(ctx);
return parser.parse();
}
*/
#!/bin/sh
/usr/local/bin/bison -S lalr1.cc --defines=cliparser_impl.h -o cliparser_impl.cpp cliparser.y
/usr/local/bin/flex --c++ --header-file=clilexer_impl.h -o clilexer_impl.cpp clilexer.l
clang++ -std=c++14 -o cliparser cliparser.cpp cliparser_impl.cpp clilexer_impl.cpp
/**
* Command line
* @author Tobias Weber <tweber@ill.fr>
* @date 31-May-2018
* @license see 'LICENSE' file
*/
#include "command.h"
#include <QtWidgets/QGridLayout>
// ----------------------------------------------------------------------------
CommandLineWidget::CommandLineWidget(QWidget *pParent, QSettings *pSettings)
: QWidget(pParent), m_pSettings(pSettings)
{
m_pEditHistory->setReadOnly(true);
m_pEditHistory->setUndoRedoEnabled(false);
// ------------------------------------------------------------------------
// layout
auto *pGrid = new QGridLayout(this);
pGrid->addWidget(m_pEditHistory, 0, 0, 1, 1);
pGrid->addWidget(m_pEditCLI, 1, 0, 1, 1);
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// connections
connect(m_pEditCLI, &QLineEdit::returnPressed, this, &CommandLineWidget::CommandEntered);
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// settings
if(m_pSettings)
{
}
// ------------------------------------------------------------------------
}
CommandLineWidget::~CommandLineWidget()
{
}
void CommandLineWidget::CommandEntered()
{
QString cmd = m_pEditCLI->text().trimmed();
m_pEditCLI->clear();
if(!cmd.length()) return;
m_pEditHistory->insertHtml(cmd + "<br>");
auto caret = m_pEditHistory->textCursor();
caret.movePosition(QTextCursor::End, QTextCursor::MoveAnchor, 1);
m_pEditHistory->setTextCursor(caret);
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
CommandLine::CommandLine(QWidget* pParent, QSettings *pSettings)
: QDockWidget(pParent), m_pCLI(std::make_unique<CommandLineWidget>(this, pSettings))
{
this->setObjectName("commandLine");
this->setWindowTitle("Command Line");
this->setWidget(m_pCLI.get());
}
CommandLine::~CommandLine()
{
}
// ----------------------------------------------------------------------------
/**
* Command line
* @author Tobias Weber <tweber@ill.fr>
* @date 31-May-2018
* @license see 'LICENSE' file
*/
#ifndef __CLI_WND_H__
#define __CLI_WND_H__
#include <QtCore/QSettings>
#include <QtWidgets/QWidget>
#include <QtWidgets/QDockWidget>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QTextEdit>
#include <memory>
/**
* command line widget
*/
class CommandLineWidget : public QWidget
{
private:
QSettings *m_pSettings = nullptr;
QTextEdit *m_pEditHistory = new QTextEdit(this);
QLineEdit *m_pEditCLI = new QLineEdit(this);
protected:
void CommandEntered();
public:
CommandLineWidget(QWidget *pParent = nullptr, QSettings *pSettings = nullptr);
virtual ~CommandLineWidget();
};
/**
* the dock which contains the command line widget
*/
class CommandLine : public QDockWidget
{
private:
std::unique_ptr<CommandLineWidget> m_pCLI;
public:
CommandLine(QWidget* pParent = nullptr, QSettings *pSettings = nullptr);
virtual ~CommandLine();
};
#endif
......@@ -35,11 +35,10 @@ public:
FileBrowserWidget(QWidget *pParent = nullptr, QSettings *pSettings = nullptr);
virtual ~FileBrowserWidget();
public:
protected:
void SelectFolder();
void SetFolder(const QString& str);
protected:
void SetFile(QListWidgetItem *pCur);
void SetMultiSelect(int checked);
......
......@@ -12,7 +12,8 @@
MainWnd::MainWnd(QSettings* pSettings)
: QMainWindow(), m_pSettings(pSettings),
m_pBrowser(new FileBrowser(this, pSettings)),
m_pWS(new WorkSpace(this, pSettings))
m_pWS(new WorkSpace(this, pSettings)),
m_pCLI(new CommandLine(this, pSettings))
{
this->setObjectName("in20");
this->setWindowTitle("IN20 Tool");
......@@ -33,6 +34,11 @@ MainWnd::MainWnd(QSettings* pSettings)
connect(pShowWorkSpace, &QAction::triggered, m_pWS, &FileBrowser::show);
pMenuView->addAction(pShowWorkSpace);
QAction *pShowCommandLine = new QAction("Show Command Line", pMenuView);
pShowCommandLine->setChecked(m_pCLI->isVisible());
connect(pShowCommandLine, &QAction::triggered, m_pCLI, &CommandLine::show);
pMenuView->addAction(pShowCommandLine);
m_pMenu->addMenu(pMenuView);
this->setMenuBar(m_pMenu);
// ------------------------------------------------------------------------
......@@ -42,6 +48,7 @@ MainWnd::MainWnd(QSettings* pSettings)
this->setCentralWidget(m_pMDI);
this->addDockWidget(Qt::LeftDockWidgetArea, m_pBrowser);
this->addDockWidget(Qt::RightDockWidgetArea, m_pWS);
this->addDockWidget(Qt::BottomDockWidgetArea, m_pCLI);
// ------------------------------------------------------------------------
......
......@@ -16,6 +16,7 @@
#include "filebrowser.h"
#include "workspace.h"
#include "command.h"
class MainWnd : public QMainWindow
......@@ -27,6 +28,7 @@ private:
QMdiArea *m_pMDI = new QMdiArea(this);
FileBrowser *m_pBrowser = nullptr;
WorkSpace *m_pWS = nullptr;
CommandLine *m_pCLI = nullptr;
private:
virtual void showEvent(QShowEvent *pEvt) override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment