Skip to content

Commit

Permalink
fixed to skip if a character cannot be typed directly (#78, #151)
Browse files Browse the repository at this point in the history
  • Loading branch information
pit-ray committed Aug 5, 2023
1 parent 97e8046 commit b00a9d7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
41 changes: 25 additions & 16 deletions src/bind/syscmd/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace
return text ;
}

std::error_code do_runcommand(
void do_runcommand(
const std::string& cmd,
const std::string& args,
const std::filesystem::path& parent_path,
Expand All @@ -131,42 +131,42 @@ namespace
switch(rcindex) {
case RunCommandsIndex::SET: {
Set::sprocess(1, cmd + " " + args) ;
return std::error_code() ;
return ;
}
case RunCommandsIndex::COMMAND: {
Command::sprocess(1, cmd + " " + args, as_default) ;
return std::error_code() ;
return ;
}
case RunCommandsIndex::DELCOMMAND: {
Delcommand::sprocess(1, cmd + " " + args, as_default) ;
return std::error_code() ;
return ;
}
case RunCommandsIndex::COMCLEAR: {
if(!args.empty()) {
return std::make_error_code(std::errc::invalid_argument) ;
throw std::make_error_code(std::errc::invalid_argument) ;
}
Comclear::sprocess(1, "", as_default) ;
return std::error_code() ;
return ;
}
case RunCommandsIndex::SOURCE: {
if(args.empty()) {
return std::make_error_code(std::errc::invalid_argument) ;
throw std::make_error_code(std::errc::invalid_argument) ;
}

auto path = \
parent_path / std::filesystem::u8path(core::replace_path_magic(args)) ;

if(std::filesystem::exists(path)) {
if(std::filesystem::equivalent(core::RC(), path)) {
return std::make_error_code(std::errc::text_file_busy) ;
throw std::make_error_code(std::errc::text_file_busy) ;
}
Source::sprocess(1, cmd + " " + path.u8string(), as_default) ;
}
else if(path.filename().u8string() != ".vindrc") {
Source::sprocess(1, cmd + " " + load_remote_vindrc(args).u8string()) ;
}

return std::error_code() ;
return ;
}
default: {
break ;
Expand All @@ -188,15 +188,14 @@ namespace
}
else if(util::enum_has_bits(rcindex, RunCommandsIndex::MASK_MAPCLEAR)) {
if(!args.empty()) {
return std::make_error_code(std::errc::invalid_argument) ;
throw std::make_error_code(std::errc::invalid_argument) ;
}
auto [prefix, _] = core::divide_prefix_and_cmd(cmd, "m") ;
do_mapclear(prefix, as_default) ;
}
else {
return std::make_error_code(std::errc::argument_out_of_domain) ;
throw std::make_error_code(std::errc::argument_out_of_domain) ;
}
return std::error_code() ;
}

void init_default_mapping(const std::string& tier="huge") {
Expand Down Expand Up @@ -270,8 +269,11 @@ namespace vind
continue ;
}

if(auto err = do_runcommand(cmd, line_args, path.parent_path(), as_default)) {
auto ltag = "L:" + std::to_string(lnum) ;
auto ltag = "L:" + std::to_string(lnum) ;
try {
do_runcommand(cmd, line_args, path.parent_path(), as_default) ;
}
catch(const std::error_code& err) {
std::stringstream cmdline_ss ;
std::stringstream log_ss ;

Expand All @@ -291,13 +293,20 @@ namespace vind
cmdline_ss << " (" << ltag << ")" ;
opt::VCmdLine::print(opt::ErrorMessage(cmdline_ss.str())) ;

log_ss << " (" << path.u8string() << ", " << ltag << ") " ;
PRINT_ERROR(log_ss.str()) ;
log_ss << " (" << path.u8string() << ", " << ltag << ")" ;
core::Logger::get_instance().error(log_ss.str()) ;

core::InputHub::get_instance().clear_mapping(
core::Mode::UNDEFINED, as_default) ;
break ;
}
catch(const std::runtime_error& e) {
std::stringstream log_ss ;
log_ss << cmd << ": " << e.what() ;
log_ss << " (" << path.u8string() << ", " << ltag << ")" ;
core::Logger::get_instance().error(log_ss.str()) ;
continue ;
}
}

// If the .vindrc is empty, apply a default tier.
Expand Down
3 changes: 2 additions & 1 deletion src/core/errlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ namespace vind
if(size > 0) {
LocalFree(msgbuf) ;
}

pimpl->stream_ << std::endl ;
}
pimpl->stream_ << std::endl ;

pimpl->stream_ << "[Error] " << msg ;
if(!scope.empty()) {
Expand Down
6 changes: 5 additions & 1 deletion src/core/keycode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <cctype>
#include <initializer_list>
#include <limits>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
Expand Down Expand Up @@ -484,7 +485,10 @@ namespace vind
auto keycode = static_cast<unsigned char>(res & 0x00ff) ;

if(keycode == 0xff) {
return KeyCode{} ;
std::stringstream ss ;
ss << "The specified letter `" << ascii << "`" ;
ss << " cannot be typed directly in your keyboard layout." ;
throw std::runtime_error(ss.str()) ;
}

return KeyCode{keycode} ;
Expand Down

0 comments on commit b00a9d7

Please sign in to comment.