OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [gui_plugin/] [ControlWidget/] [ConsoleWidget.cpp] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 sergeykhbr
#include "ConsoleWidget.h"
2
#include "moc_ConsoleWidget.h"
3
 
4
#include <QtCore/QDate>
5
#include <QtGui/QPainter>
6
#include <QtWidgets/QScrollBar>
7
#include <memory>
8
 
9
namespace debugger {
10
 
11
static const char CONSOLE_ENTRY[] = "riscv# ";
12
 
13
ConsoleWidget::ConsoleWidget(IGui *igui, QWidget *parent)
14
    : QPlainTextEdit(parent) {
15
    igui_ = igui;
16
 
17
    RISCV_mutex_init(&mutexOutput_);
18
    sizeConv_ = 1024;
19
    wcsConv_ = new wchar_t[sizeConv_];
20
    mbsConv_ = new char[sizeConv_];
21
 
22
    clear();
23
    fontMainText_ = QFont("Courier");
24
    fontMainText_.setStyleHint(QFont::Monospace);
25
    fontMainText_.setPointSize(9);
26
    fontMainText_.setFixedPitch(true);
27
    setFont(fontMainText_);
28
 
29
    fontRISCV_ = fontMainText_;
30
    fontRISCV_.setBold(true);
31
 
32
    ensureCursorVisible();
33
 
34
    QTextCursor cursor = textCursor();
35
    QTextCharFormat charFormat = cursor.charFormat();
36
    charFormat.setFont(fontRISCV_);
37
    cursor.setCharFormat(charFormat);
38
 
39 4 sergeykhbr
    cursor.insertText(tr(
40
    "**********************************************************\n"
41
    "  RISC-V debugger\n"
42
    "  Author: Sergey Khabarov - sergeykhbr@gmail.com\n"
43
    "  Copyright 2017 GNSS Sensor Ltd. All right reserved.\n"
44
    "**********************************************************\n"));
45 3 sergeykhbr
 
46
    cursor.insertText(tr(CONSOLE_ENTRY));
47
    cursorMinPos_ = cursor.selectionStart();
48
 
49
    charFormat.setFont(fontMainText_);
50
    cursor.setCharFormat(charFormat);
51
    setTextCursor(cursor);
52
    setWindowTitle(tr("simconsole"));
53
 
54
    cursorPos_.make_list(2);
55
    cursorPos_[0u].make_int64(0);
56
    cursorPos_[1].make_int64(0);
57
 
58
    connect(this, SIGNAL(signalNewData()), this, SLOT(slotUpdateByData()));
59
 
60
    const char *autoobj = (*igui_->getpConfig())["AutoComplete"].to_string();
61
    iauto_ = static_cast<IAutoComplete *>(
62
        RISCV_get_service_iface(autoobj, IFACE_AUTO_COMPLETE));
63
 
64
    RISCV_add_default_output(static_cast<IRawListener *>(this));
65
}
66
 
67
ConsoleWidget::~ConsoleWidget() {
68
    igui_->removeFromQueue(static_cast<IGuiCmdHandler *>(this));
69
    RISCV_remove_default_output(static_cast<IRawListener *>(this));
70
    RISCV_mutex_destroy(&mutexOutput_);
71
    delete [] wcsConv_;
72
    delete [] mbsConv_;
73
}
74
 
75
void ConsoleWidget::handleResponse(AttributeType *req, AttributeType *resp) {
76
    if (resp->is_nil() || resp->is_invalid()) {
77
        return;
78
    }
79
    RISCV_mutex_lock(&mutexOutput_);
80 4 sergeykhbr
    strOutput_ += QString(resp->to_config().to_string()) + "\n";
81 3 sergeykhbr
    RISCV_mutex_unlock(&mutexOutput_);
82
    emit signalNewData();
83
}
84
 
85
void ConsoleWidget::keyPressEvent(QKeyEvent *e) {
86
    AttributeType cmd;
87
    QTextCursor cursor = textCursor();
88
    uint32_t vt_key = static_cast<uint32_t>(e->nativeVirtualKey());
89
    char vt_char = static_cast<char>(vt_key);
90
    if (vt_char >= 'A' && vt_char <= 'Z' && e->modifiers() == Qt::NoModifier) {
91
        vt_key -= static_cast<uint32_t>('A');
92
        vt_key += static_cast<uint32_t>('a');
93 4 sergeykhbr
    }
94
    uint8_t spsmb = static_cast<uint8_t>(e->text().at(0).toLatin1());
95
    if (spsmb == '_' || vt_key == ':' || vt_key == '\\' || vt_key == '/') {
96
        vt_key = spsmb;
97 3 sergeykhbr
    }
98
    //printf("vt_key = %08x\n", vt_key);
99
    bool cmd_ready = iauto_->processKey(vt_key, &cmd, &cursorPos_);
100
 
101
    moveCursor(QTextCursor::End);
102
    cursor = textCursor();
103
    cursor.setPosition(cursorMinPos_, QTextCursor::KeepAnchor);
104
    cursor.insertText(cmd.to_string());
105
    if (cursorPos_[0u].to_int()) {
106
        cursor.movePosition(QTextCursor::Left,
107
                QTextCursor::MoveAnchor, cursorPos_[0u].to_int());
108
        setTextCursor(cursor);
109
    }
110
 
111
    if (!cmd_ready) {
112
        return;
113
    }
114
    cursor.movePosition(QTextCursor::End);
115
    cursor.insertText(tr("\r"));
116
 
117
    QTextCharFormat charFormat = cursor.charFormat();
118
    cursor.insertText(tr(CONSOLE_ENTRY));
119
    cursorMinPos_ = cursor.selectionStart();
120
    verticalScrollBar()->setValue(verticalScrollBar()->maximum());
121
 
122
    igui_->registerCommand(
123
        static_cast<IGuiCmdHandler *>(this), &cmd, false);
124
}
125
 
126
void ConsoleWidget::slotUpdateByData() {
127
    if (strOutput_.size() == 0) {
128
        return;
129
    }
130
    // Keep current line value:
131
    QTextCursor cursor = textCursor();
132
    cursor.movePosition(QTextCursor::End);
133
    cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
134
    QString cur_line = cursor.selectedText();
135
    // Insert raw string:
136
    RISCV_mutex_lock(&mutexOutput_);
137
    cursor.insertText(strOutput_);
138
    cursorMinPos_ += strOutput_.size();
139
    strOutput_.clear();
140
    RISCV_mutex_unlock(&mutexOutput_);
141
 
142
    // Restore line:
143
    cursor.movePosition(QTextCursor::End);
144
    cursor.insertText(cur_line);
145
    // Restore cursor position:
146
    cursor.movePosition(QTextCursor::End);
147
    cursor.movePosition(QTextCursor::Left,
148
           QTextCursor::MoveAnchor, cursorPos_[0u].to_int());
149
    setTextCursor(cursor);
150
 
151
    verticalScrollBar()->setValue(verticalScrollBar()->maximum());
152
}
153
 
154
void ConsoleWidget::updateData(const char *buf, int bufsz) {
155
    RISCV_mutex_lock(&mutexOutput_);
156
    strOutput_ += QString(buf);
157
    RISCV_mutex_unlock(&mutexOutput_);
158
    emit signalNewData();
159
}
160
 
161
}  // namespace debugger

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.