Skip to content

Commit

Permalink
Add ^P^{A,D,F} support for macros in the FSED.
Browse files Browse the repository at this point in the history
To use a macro, press control-P then the normal macro character.
This is because control A, control D are all used.
  • Loading branch information
wwiv committed Nov 7, 2020
1 parent 9faa3c4 commit aa2033d
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 43 deletions.
1 change: 0 additions & 1 deletion bbs/automsg.cpp
Expand Up @@ -26,7 +26,6 @@
#include "common/com.h"
#include "bbs/email.h"
#include "bbs/sysoplog.h"
#include "bbs/utility.h"
#include "common/quote.h"
#include "common/input.h"
#include "common/output.h"
Expand Down
8 changes: 4 additions & 4 deletions bbs/msgscan.cpp
Expand Up @@ -333,7 +333,7 @@ static FullScreenView CreateFullScreenListTitlesView() {
a()->current_sub().name, a()->GetNumMessagesInCurrentMessageArea()));
bout.format("|14 Num {:<42} From\r\n", "Title");
bout.clear_lines_listed();
return FullScreenView(bout, num_header_lines, screen_width, screen_length);
return FullScreenView(bout, bin, num_header_lines, screen_width, screen_length);
}

static std::string CreateLine(std::unique_ptr<wwiv::sdk::msgapi::Message>&& msg, const int msgnum) {
Expand Down Expand Up @@ -417,18 +417,18 @@ static void display_title_new(const std::vector<std::string>& lines, const FullS

static void display_titles_new(const std::vector<std::string>& lines, const FullScreenView& fs,
int start, int selected) {
for (int i = 0; i < fs.message_height(); i++) {
for (auto i = 0; i < fs.message_height(); i++) {
if (i >= ssize(lines)) {
break;
}
bool is_selected = i == (selected - start);
const auto is_selected = i == selected - start;
display_title_new(lines, fs, i, is_selected);
}
}

static ReadMessageResult HandleListTitlesFullScreen(int& msgnum, MsgScanOption& scan_option_type) {
bout.cls();
auto api = a()->msgapi();
auto* api = a()->msgapi();
unique_ptr<MessageArea> area(
api->Open(a()->current_sub(), a()->sess().GetCurrentReadMessageArea()));
if (!area) {
Expand Down
4 changes: 2 additions & 2 deletions bbs/read_message.cpp
Expand Up @@ -418,7 +418,7 @@ static FullScreenView display_type2_message_header(Type2MessageData& msg) {
}
if (!msg.from_sys_loc.empty()) {
auto loc = msg.from_sys_loc;
const int maxlen = a()->user()->GetScreenChars() - 7 - COLUMN2;
const auto maxlen = a()->user()->GetScreenChars() - 7 - COLUMN2;
if (ssize(loc) > maxlen) {
loc = loc.substr(0, maxlen);
}
Expand Down Expand Up @@ -465,7 +465,7 @@ static FullScreenView display_type2_message_header(Type2MessageData& msg) {
const auto screen_length = a()->user()->GetScreenLines() - 1;

bout.SystemColor(oldcuratr);
return FullScreenView(bout, num_header_lines, screen_width, screen_length);
return FullScreenView(bout, bin, num_header_lines, screen_width, screen_length);
}

static std::vector<std::string> split_wwiv_message(const std::string& orig_text, bool controlcodes) {
Expand Down
9 changes: 5 additions & 4 deletions common/full_screen.cpp
Expand Up @@ -37,14 +37,15 @@ using namespace wwiv::strings;

namespace wwiv::common {

FullScreenView::FullScreenView(Output& output, int numlines, int swidth, int slength)
: bout_(output), num_header_lines_(numlines), screen_width_(swidth), screen_length_(slength) {
FullScreenView::FullScreenView(Output& output, Input& input, int numlines, int swidth, int slength)
: bout_(output), bin_(input), num_header_lines_(numlines), screen_width_(swidth),
screen_length_(slength) {
message_height_ = screen_length_ - num_header_lines_ - 2 - 1;
lines_start_ = num_header_lines_ + 2;
lines_end_ = lines_start_ + message_height_;
command_line_ = screen_length_;

//Save the topdata.
// Save the topdata.
saved_topdata = output.localIO()->topdata();
if (output.localIO()->topdata() != LocalIO::topdata_t::none) {
output.localIO()->topdata(LocalIO::topdata_t::none);
Expand Down Expand Up @@ -96,7 +97,7 @@ void FullScreenView::DrawBottomBar(const std::string& text) {
const auto y = screen_length_ - 1;
bout_.GotoXY(1, y);
const auto saved_color = bout.curatr();
wwiv::core::ScopeExit at_ext([=] { bout.SystemColor(saved_color); });
ScopeExit at_ext([=] { bout.SystemColor(saved_color); });

bout_ << "|09" << static_cast<unsigned char>(198)
<< string(screen_width_ - 2, static_cast<unsigned char>(205))
Expand Down
22 changes: 13 additions & 9 deletions common/full_screen.h
Expand Up @@ -15,18 +15,19 @@
/* either express or implied. See the License for the specific */
/* language governing permissions and limitations under the License. */
/**************************************************************************/
#ifndef __INCLUDED_COMMON_FULL_SCREEN_H__
#define __INCLUDED_COMMON_FULL_SCREEN_H__
#ifndef INCLUDED_COMMON_FULL_SCREEN_H
#define INCLUDED_COMMON_FULL_SCREEN_H

#include "local_io/local_io.h"
#include <string>

namespace wwiv::common {
class Input;
class Output;

class FullScreenView final {
public:
FullScreenView(wwiv::common::Output& output, int numlines, int swidth, int slength);
FullScreenView(Output& output, Input& input, int numlines, int swidth, int slength);
~FullScreenView();

/** Displays a timeout warning in the command line area */
Expand All @@ -44,20 +45,23 @@ class FullScreenView final {
/** Places the cursor at the top of the body */
void GotoContentAreaTop();

int message_height() const noexcept { return message_height_; }
int lines_start() const noexcept { return lines_start_; }
int lines_end() const noexcept { return lines_end_; }
int num_header_lines() const noexcept { return num_header_lines_; }
int screen_width() const noexcept { return screen_width_; }
[[nodiscard]] int message_height() const noexcept { return message_height_; }
[[nodiscard]] int lines_start() const noexcept { return lines_start_; }
[[nodiscard]] int lines_end() const noexcept { return lines_end_; }
[[nodiscard]] int num_header_lines() const noexcept { return num_header_lines_; }
[[nodiscard]] int screen_width() const noexcept { return screen_width_; }

// Runs bgetch_event with error message and warning displayed
// on the status line.
int bgetch();

// Read through to this full screen's input.
[[nodiscard]] Input& in() const { return bin_; }
// Write through to this full screen's output.
Output& out() const { return bout_; }
[[nodiscard]] Output& out() const { return bout_; }

private:
Input& bin_;
Output& bout_;

int num_header_lines_{0};
Expand Down
2 changes: 0 additions & 2 deletions common/input.h
Expand Up @@ -19,11 +19,9 @@
#ifndef __INCLUDED_COMMON_INPUT_H__
#define __INCLUDED_COMMON_INPUT_H__

#include "core/strings.h"
#include "common/iobase.h"
#include "common/context.h"
#include "common/remote_io.h"
#include "sdk/user.h"
#include <chrono>
#include <functional>
#include <set>
Expand Down
6 changes: 3 additions & 3 deletions common/macro_context.h
Expand Up @@ -25,14 +25,14 @@ namespace wwiv::common {

class MacroContext {
public:
MacroContext(wwiv::common::Context* context) : context_(context) {}
explicit MacroContext(Context* context) : context_(context) {}
virtual ~MacroContext() = default;

virtual std::string interpret(char c) const = 0;
wwiv::common::Context* context() { return context_; }
Context* context() { return context_; }

protected:
wwiv::common::Context* context_{nullptr};
Context* context_{nullptr};
};

} // namespace wwiv::common
Expand Down
8 changes: 7 additions & 1 deletion fsed/commands.cpp
Expand Up @@ -49,6 +49,7 @@ std::map<int, fsed_command_id> CreateDefaultEditModeKeyMap() {
map.emplace(ESC, fsed_command_id::menu);
map.emplace(CI, fsed_command_id::toggle_insovr);
map.emplace(RETURN, fsed_command_id::key_return);
map.emplace(SOFTRETURN, fsed_command_id::ignore);
map.emplace(CP, fsed_command_id::input_wwiv_color);
map.emplace(CW, fsed_command_id::delete_word_left);
map.emplace(CX, fsed_command_id::delete_line_left);
Expand Down Expand Up @@ -184,10 +185,12 @@ bool FsedCommands::AddAll() {
return true;
}));
add(FsedCommand(fsed_command_id::input_wwiv_color, "input_wwiv_color",
[](FsedModel& ed, FsedView& view, FsedState&) -> bool {
[&](FsedModel& ed, FsedView& view, FsedState&) -> bool {
const auto cc = view.bgetch(ed);
if (cc >= '0' && cc <= '9') {
ed.curline().set_wwiv_color(cc - '0');
} else if (cc == CA || cc == CD || cc == CF) {
view.macro(ctx_, cc);
}
ed.current_line_dirty(ed.curli);
return true;
Expand All @@ -204,6 +207,9 @@ bool FsedCommands::AddAll() {
return true;
}));

add(FsedCommand(
fsed_command_id::ignore, "ignore",
[](FsedModel&, FsedView&, FsedState&) -> bool { return true; }));
return false;
}

Expand Down
1 change: 1 addition & 0 deletions fsed/commands.h
Expand Up @@ -50,6 +50,7 @@ enum class fsed_command_id {
toggle_insovr,
view_redraw,
input_wwiv_color,
ignore,
none,
};

Expand Down
3 changes: 2 additions & 1 deletion fsed/fsed.cpp
Expand Up @@ -18,6 +18,7 @@
#include "fsed/fsed.h"

#include "common/full_screen.h"
#include "common/input.h"
#include "common/message_editor_data.h"
#include "common/output.h"
#include "core/eventbus.h"
Expand All @@ -42,7 +43,7 @@ static std::shared_ptr<FsedView> create_frame(MessageEditorData& data, bool file
const auto screen_width = (user != nullptr) ? user->GetScreenChars() : 80;
const auto screen_length = (user != nullptr) ? user->GetScreenLines() - 1 : 24;
const auto num_header_lines = 4;
auto fs = FullScreenView(bout, num_header_lines, screen_width, screen_length);
auto fs = FullScreenView(bout, bin, num_header_lines, screen_width, screen_length);
auto view = std::make_shared<FsedView>(fs, data, file);
view->redraw();
return view;
Expand Down
16 changes: 8 additions & 8 deletions fsed/line.cpp
Expand Up @@ -30,11 +30,11 @@ using namespace wwiv::strings;
enum class add_cell_state_t { text, heart_color };

line_t::line_t(bool wrapped, std::string text) : wrapped_(wrapped) {
add_cell_state_t state = add_cell_state_t::text;
auto state = add_cell_state_t::text;
for (const auto c : text) {
if (state == add_cell_state_t::heart_color) {
state = add_cell_state_t::text;
auto color = static_cast<int>(c - '0');
const auto color = static_cast<int>(c - '0');
if (color >= 0 && color <= 9) {
wwiv_color_ = color;
}
Expand All @@ -61,27 +61,27 @@ line_add_result_t line_t::add(int x, char c, ins_ovr_mode_t mode) {
if (x == size_) {
push_back(c);
return line_add_result_t::no_redraw;
} else if (mode == ins_ovr_mode_t::ins) {
}
if (mode == ins_ovr_mode_t::ins) {
wwiv::stl::insert_at(cell_, x, cell_t{wwiv_color_, c});
++size_;
return line_add_result_t::needs_redraw;
} else {
cell_[x] = cell_t{wwiv_color_, c};
return line_add_result_t::no_redraw;
}
cell_[x] = cell_t{wwiv_color_, c};
return line_add_result_t::no_redraw;
}

line_add_result_t line_t::del(int x, ins_ovr_mode_t) {
if (x < 0) {
return line_add_result_t::error;
}
auto result = (x == size_) ? line_add_result_t::no_redraw : line_add_result_t::needs_redraw;
const auto result = x == size_ ? line_add_result_t::no_redraw : line_add_result_t::needs_redraw;
if (!wwiv::stl::erase_at(cell_, x)) {
return line_add_result_t ::error;
}
--size_;

auto new_x = x - 1;
const auto new_x = x - 1;
if (new_x >= 0 && new_x < size_) {
// adopt new color
wwiv_color_ = cell_.at(new_x).wwiv_color;
Expand Down
34 changes: 32 additions & 2 deletions fsed/view.cpp
Expand Up @@ -27,15 +27,16 @@
#include "core/strings.h"
#include "core/textfile.h"
#include "fmt/format.h"
#include "local_io/keycodes.h"

using namespace wwiv::common;
using namespace wwiv::stl;
using namespace wwiv::strings;

namespace wwiv::fsed {

FsedView::FsedView(FullScreenView fs, MessageEditorData& data, bool file)
: fs_(std::move(fs)), bout_(fs_.out()), data_(data), file_(file) {
FsedView::FsedView(const FullScreenView& fs, MessageEditorData& data, bool file)
: fs_(fs), bout_(fs_.out()), bin_(fs_.in()), data_(data), file_(file) {
max_view_lines_ = std::min<int>(20, fs.message_height() - 1);
max_view_columns_ = std::min<int>(fs.screen_width(), 79);
}
Expand All @@ -50,6 +51,21 @@ void FsedView::ClearCommandLine() {
fs_.PutsCommandLine("|#9(|#2ESC|#9=Menu/Help) ");
}

void FsedView::macro(Context& ctx, int cc) {
if (!ctx.session_context().okmacro() || bin.charbufferpointer_) {
return;
}
std::map<int, int> macro_nums{{CD, 0}, {CF, 1}, {CA, 2}};
const auto macro_num = macro_nums.at(cc);
const auto m = ctx.u().GetMacro(macro_num);
if (m.empty()) {
return;
}
strcpy(&bin.charbuffer[1], m.c_str());
bin.charbufferpointer_ = 1;

}

void FsedView::draw_current_line(FsedModel& ed, int previous_line) {
if (previous_line != ed.curli) {
const auto py = previous_line - top_line() + fs_.lines_start();
Expand Down Expand Up @@ -170,6 +186,20 @@ void FsedView::draw_bottom_bar(const FsedModel& ed) {
}

int FsedView::bgetch(FsedModel& ed) {
// bgetch_event doesn't process macros by design, but
// we want them in the FSED
if (bin_.charbufferpointer_) {
if (!bin_.charbuffer[bin_.charbufferpointer_]) {
bin_.charbufferpointer_ = 0;
bin_.charbuffer[0] = 0;
} else {
if (bin_.charbuffer[bin_.charbufferpointer_] == CC) {
bin_.charbuffer[bin_.charbufferpointer_] = CP;
}
return bin_.charbuffer[bin_.charbufferpointer_++];
}
}

return bin.bgetch_event(Input::numlock_status_t::NUMBERS, std::chrono::seconds(1),
[&](Input::bgetch_timeout_status_t status, int s) {
if (status == Input::bgetch_timeout_status_t::WARNING) {
Expand Down
10 changes: 9 additions & 1 deletion fsed/view.h
Expand Up @@ -22,11 +22,17 @@
#include "common/message_editor_data.h"
#include "fsed/model.h"

namespace wwiv {
namespace common {
class Context;
}
}

namespace wwiv::fsed {

class FsedView final : public editor_viewport_t {
public:
FsedView(common::FullScreenView fs, common::MessageEditorData& data, bool file);
FsedView(const common::FullScreenView& fs, common::MessageEditorData& data, bool file);
~FsedView() override = default;

common::FullScreenView& fs();
Expand All @@ -50,6 +56,7 @@ class FsedView final : public editor_viewport_t {
void set_top_line(int l) override { top_line_ = l; }
void gotoxy(const FsedModel& ed) override;
void ClearCommandLine();
void macro(wwiv::common::Context& ctx, int cc);

// Top editor line number visible in the viewport.
int top_line_{0};
Expand All @@ -58,6 +65,7 @@ class FsedView final : public editor_viewport_t {
private:
common::FullScreenView fs_;
common::Output& bout_;
common::Input& bin_;
int max_view_lines_;
int max_view_columns_;
common::MessageEditorData& data_;
Expand Down

0 comments on commit aa2033d

Please sign in to comment.