Skip to content

Commit

Permalink
Drop fmt dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
magiblot committed Jun 10, 2023
1 parent e119120 commit 37f62a7
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 31 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Expand Up @@ -3,7 +3,6 @@ cmake_minimum_required (VERSION 3.5)
option(TURBO_BUILD_APP "Build main editor application" ON)
option(TURBO_BUILD_TESTS "Build and run tests" OFF)
option(TURBO_BUILD_EXAMPLES "Build example apps" OFF)
option(TURBO_USE_SYSTEM_DEPS "Use system-wide dependencies instead of submodules (except Turbo Vision)" OFF)
option(TURBO_USE_SYSTEM_TVISION "Use system-wide Turbo Vision instead of the submodule" OFF)
option(TURBO_USE_STATIC_RTL "Link against the static version of the runtime library (MSVC only)" OFF)
option(TURBO_OPTIMIZE_BUILD "Use Precompiled Headers and Unity Build for the core library" ON)
Expand Down Expand Up @@ -107,11 +106,9 @@ target_include_directories(${TURBO}-core PRIVATE
)
target_link_libraries(${TURBO}-core PUBLIC
tvision
fmt
)

if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13.0")
install(TARGETS fmt EXPORT ${TURBO}-config)
install(TARGETS ${TURBO}-core
EXPORT ${TURBO}-config
ARCHIVE DESTINATION lib
Expand Down Expand Up @@ -175,7 +172,6 @@ if (TURBO_BUILD_TESTS)
find_library(GTEST_MAIN gtest_main REQUIRED)
target_link_libraries(${TURBO}-test PRIVATE
${TURBO}-core
fmt
${GTEST}
${GTEST_MAIN}
)
Expand Down
6 changes: 0 additions & 6 deletions deps/CMakeLists.txt
Expand Up @@ -18,12 +18,6 @@ function(turbo_find_library name header)
target_include_directories(${name} INTERFACE ${${name}_INCLUDE})
endfunction()

if (TURBO_USE_SYSTEM_DEPS)
turbo_find_library(fmt "fmt/core.h")
else()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/fmt" EXCLUDE_FROM_ALL)
endif()

set(TV_OPTIMIZE_BUILD ${TURBO_OPTIMIZE_BUILD})
if (TURBO_USE_SYSTEM_TVISION)
find_package(tvision CONFIG REQUIRED)
Expand Down
1 change: 0 additions & 1 deletion deps/fmt
Submodule fmt deleted from b6f4ce
5 changes: 2 additions & 3 deletions source/turbo-core/editstates.cc
@@ -1,7 +1,6 @@
#define Uses_MsgBox
#include <tvision/tv.h>

#include <fmt/core.h>
#include <turbo/editstates.h>
#include <turbo/scintilla.h>
#include <turbo/scintilla/internals.h>
Expand Down Expand Up @@ -61,8 +60,8 @@ void WrapState::setState(bool enable, TScintilla &scintilla, TFuncView<bool(int)

bool WrapState::defConfirmWrap(int width)
{
auto &&text = fmt::format("This document is quite large and the longest of its lines is at least {} characters long.\nAre you sure you want to enable line wrapping?", width);
return messageBox(text, mfInformation | mfYesButton | mfNoButton) == cmYes;
return cmYes == messageBox( mfInformation | mfYesButton | mfNoButton,
"This document is quite large and the longest of its lines is at least %d characters long.\nAre you sure you want to enable line wrapping?", width );
}

/////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 10 additions & 5 deletions source/turbo-core/fileeditor.cc
Expand Up @@ -4,9 +4,9 @@
#include <turbo/fileeditor.h>
#include <turbo/tpath.h>

#include <fmt/core.h>
#include <memory>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
Expand Down Expand Up @@ -342,8 +342,12 @@ static bool canOverwrite(FileDialogs &dlgs, const char *path) noexcept
void ShowAllDialogs::getSaveAsPath(FileEditor &editor, TFuncView<bool (const char *)> accept) noexcept
{
char path[MAXPATH];
auto &&title = editor.filePath.empty() ? "Save untitled file" : fmt::format("Save file '{}' as", TPath::basename(editor.filePath));
openFileDialog("*.*", title, "~N~ame", fdOKButton, 0, [&] (TView *dialog) {
std::ostringstream os;
if (editor.filePath.empty())
os << "Save untitled file";
else
os << "Save file '" << TPath::basename(editor.filePath) << "' as";
openFileDialog("*.*", os.str(), "~N~ame", fdOKButton, 0, [&] (TView *dialog) {
dialog->getData(path);
fexpand(path);
return canOverwrite(*this, path) && accept(path);
Expand All @@ -353,8 +357,9 @@ void ShowAllDialogs::getSaveAsPath(FileEditor &editor, TFuncView<bool (const cha
void ShowAllDialogs::getRenamePath(FileEditor &editor, TFuncView<bool (const char *)> accept) noexcept
{
char path[MAXPATH];
auto &&title = fmt::format("Rename file '{}'", TPath::basename(editor.filePath));
openFileDialog("*.*", title, "~N~ame", fdOKButton, 0, [&] (TView *dialog) {
std::ostringstream os;
os << "Rename file '" << TPath::basename(editor.filePath) << "'";
openFileDialog("*.*", os.str(), "~N~ame", fdOKButton, 0, [&] (TView *dialog) {
dialog->getData(path);
fexpand(path);
// Don't do anything if renaming to the same file. If the user needed to
Expand Down
2 changes: 0 additions & 2 deletions source/turbo/app.cc
Expand Up @@ -16,8 +16,6 @@
#define Uses_TScreen
#include <tvision/tv.h>

#include <fmt/core.h>

#include "app.h"
#include "apputils.h"
#include "editwindow.h"
Expand Down
5 changes: 2 additions & 3 deletions source/turbo/editor.cc
Expand Up @@ -4,8 +4,6 @@
#include "editor.h"
#include "editwindow.h"

#include <fmt/core.h>

void TurboEditor::onFilePathSet() noexcept
{
bool noLastLanguage = !language;
Expand All @@ -19,7 +17,8 @@ ushort TurboFileDialogs::confirmSaveUntitled(turbo::FileEditor &editor) noexcept
if (auto *window = (EditorWindow *) editor.parent)
{
auto *title = window->formatTitle(EditorWindow::tfNoSavePoint);
return messageBox(fmt::format("Save '{}'?", title), mfConfirmation | mfYesNoCancel);
return messageBox( mfConfirmation | mfYesNoCancel,
"Save '%s'?", title );
}
return super::confirmSaveUntitled(editor);
}
Expand Down
14 changes: 9 additions & 5 deletions source/turbo/editwindow.cc
Expand Up @@ -12,8 +12,8 @@
#include "apputils.h"
#include "search.h"
#include "gotoline.h"
#include <fmt/core.h>
#include <iostream>
#include <sstream>
using std::ios;

EditorWindow::EditorWindow( const TRect &bounds, TurboEditor &aEditor,
Expand Down Expand Up @@ -279,10 +279,14 @@ const char* EditorWindow::formatTitle(ushort flags) noexcept
if (lastTitleState != titleState)
{
lastTitleState = titleState;
TStringView name = !filePath().empty() ? TPath::basename(filePath()) : "Untitled";
auto &&number = fileNumber.number > 1 ? fmt::format(" ({})", fileNumber.number) : std::string();
TStringView savePoint = inSavePoint ? "" : "*";
title = fmt::format("{}{}{}", name, number, savePoint);
TStringView name = filePath().empty() ? "Untitled" : TPath::basename(filePath());
std::ostringstream os;
os << name;
if (fileNumber.number > 1)
os << " (" << fileNumber.number << ')';
if (!inSavePoint)
os << '*';
title = os.str();
}
return title.c_str();
}
Expand Down
6 changes: 4 additions & 2 deletions test/test.cc
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>

#include <fmt/core.h>
#include <test/test.h>
#include <sstream>

namespace turbo
{
Expand All @@ -10,7 +10,9 @@ TextState TextState::decode(std::string_view input)
{
size_t caret = input.find(chCaret);
if (caret == std::string_view::npos)
throw std::runtime_error(fmt::format("Input text does not have a caret: '{}'", input));
throw std::runtime_error((std::ostringstream()
<< "Input text does not have a caret: '" << input << "'"
).str());
size_t anchor = input.find(chAnchor);
if (anchor == std::string_view::npos)
anchor = caret;
Expand Down

0 comments on commit 37f62a7

Please sign in to comment.