### Building C++ Examples Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/cpp/README.md Instructions to build the C++ examples after TDLib has been pre-built and installed. ```bash cd /example/cpp mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DTd_DIR=/example/cpp/td/lib/cmake/Td .. cmake --build . ``` -------------------------------- ### Setup nchat with a protocol Source: https://github.com/d99kris/nchat/blob/master/README.md Initiates the nchat setup mode, prompting for protocol selection and phone number. Example shows Telegram setup. ```bash nchat --setup ``` -------------------------------- ### Pre-building TDLib Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/cpp/README.md Steps to pre-build and install TDLib to a local subdirectory for C++ examples. ```bash cd mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=../example/cpp/td .. cmake --build . --target install ``` -------------------------------- ### Prebuilding and Installing TDLib Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/swift/README.md Builds and installs TDLib to the local 'td/' subdirectory, which is required before building the Swift example. Ensure you are in the TDLib source directory. ```bash cd mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=../example/swift/td .. cmake --build . --target install ``` -------------------------------- ### Build and Install SQLite Modern C++ Source: https://github.com/d99kris/nchat/blob/master/lib/ncutil/ext/sqlite_modern_cpp/README.md Standard build and installation commands for the library using configure, make, and make install. ```bash ./configure && make && sudo make install ``` -------------------------------- ### CMake Minimum Required and Project Setup Source: https://github.com/d99kris/nchat/blob/master/lib/wmchat/go/CMakeLists.txt Sets the minimum required CMake version and defines the project name. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(libcgowm) ``` -------------------------------- ### Install nchat Source: https://github.com/d99kris/nchat/blob/master/doc/LOWMEMORY.md Installs the compiled nchat application system-wide using 'sudo make install'. ```bash sudo make install ``` -------------------------------- ### Start llama.cpp Server Source: https://github.com/d99kris/nchat/blob/master/doc/AUTOCOMPOSE.md Starts a llama.cpp server on port 8080, loading a specified model. ```bash llama-server --port 8080 -m ./models/llama-2-13b-chat.Q4_K_M.gguf ``` -------------------------------- ### Install Dependencies on NetBSD Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html Sets PKG_PATH and installs Git, gperf, PHP, CMake, OpenSSL, and GCC libraries. ```bash export PKG_PATH=http://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/$(uname -p)/$(uname -r)/All pkg_add -z git gperf pcre2 php-8* cmake openssl gcc12-libs mozi ``` -------------------------------- ### Build and Install nchat Source: https://github.com/d99kris/nchat/blob/master/README.md Standard commands to build and install nchat. Ensure you are in the project's root directory. ```bash ./make.sh build && ./make.sh install ``` -------------------------------- ### Setup Build Environment Source: https://github.com/d99kris/nchat/blob/master/doc/LOWMEMORY.md Creates a build directory and configures the build using CMake, specifying Clang as the C and C++ compiler. ```bash mkdir -p build && cd build CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake .. ``` -------------------------------- ### Run TDLib Python Example Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/python/README.md To run the example, ensure TDLib is built and the tdjson shared library is in the current directory. Then, execute the Python script. ```bash python tdjson_example.py ``` -------------------------------- ### Set Default Installation Directories Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Sets default installation directories for libraries, binaries, and include files if they are not already defined. ```cmake if (NOT DEFINED CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR "lib") endif() if (NOT DEFINED CMAKE_INSTALL_BINDIR) set(CMAKE_INSTALL_BINDIR "bin") endif() if (NOT DEFINED CMAKE_INSTALL_INCLUDEDIR) set(CMAKE_INSTALL_INCLUDEDIR "include") endif() ``` -------------------------------- ### Install TDNET Target Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/tdnet/CMakeLists.txt Installs the tdnet static library, its export configuration, and related files to the specified installation directories if TDNET_ENABLE_INSTALL is ON. ```cmake if (TDNET_ENABLE_INSTALL) install(TARGETS tdnet EXPORT TdStaticTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) endif() ``` -------------------------------- ### Library Definition and Installation Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/CMakeLists.txt Defines the tgchat library and installs it to the appropriate directory. ```cmake add_library(tgchat ${LIBRARY_LINKING_TYPE} src/tgchat.cpp src/tgchat.h ) install(TARGETS tgchat DESTINATION ${CMAKE_INSTALL_LIBDIR}) ``` -------------------------------- ### Install Dependencies Source: https://github.com/d99kris/nchat/blob/master/themes/templates/iterm2-color-schemes/README.md Install the required Python packages for theme generation using pip3. ```bash pip3 install rich PyYAML Jinja2 ``` -------------------------------- ### Install Theme from Web Source: https://github.com/d99kris/nchat/blob/master/README.md Download the latest theme files from the GitHub repository to the Nchat config directory. This requires curl to be installed. ```bash THEME="dracula" ; curl -L "https://raw.githubusercontent.com/d99kris/nchat/refs/heads/master/themes/${THEME}/{color.conf,usercolor.conf}" -o ~/.config/nchat/#1 ``` -------------------------------- ### Install Go Library Source: https://github.com/d99kris/nchat/blob/master/lib/sgchat/go/CMakeLists.txt Installs the built Go shared library to the appropriate system directory if static Go library is not being used. ```cmake # Install if (NOT HAS_STATICGOLIB) install(FILES ${OUTPUT_DIR}/${LIB} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() ``` -------------------------------- ### Install Dependencies on OpenBSD Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html Installs Git, gperf, PHP, CMake, and optionally JDK for JNI targets using pkg_add. ```bash pkg_add -z git gperf php-7.2.10 cmake ``` ```bash pkg_add -z jdk ``` -------------------------------- ### Install TDUtils Target Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/tdutils/CMakeLists.txt Installs the tdutils target as a library and archive to the specified installation directories. ```cmake install(TARGETS tdutils EXPORT TdStaticTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) ``` -------------------------------- ### TDLib C++ Example CMakeLists.txt Configuration Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/cpp/CMakeLists.txt Configures the build for TDLib C++ examples, including finding the TDLib package and linking libraries. ```cmake cmake_minimum_required(VERSION 3.10 FATAL_ERROR) project(TdExample VERSION 1.0 LANGUAGES CXX) find_package(Td 1.8.64 REQUIRED) add_executable(tdjson_example tdjson_example.cpp) target_link_libraries(tdjson_example PRIVATE Td::TdJson) set_property(TARGET tdjson_example PROPERTY CXX_STANDARD 11) add_executable(td_example td_example.cpp) target_link_libraries(td_example PRIVATE Td::TdStatic) set_property(TARGET td_example PROPERTY CXX_STANDARD 14) ``` -------------------------------- ### Setting up Multiple Protocols in a Single Config Source: https://github.com/d99kris/nchat/blob/master/README.md Configure multiple protocol accounts within a single nchat configuration directory by running setup mode for each. ```bash nchat -s ``` -------------------------------- ### Configure TDE2E Build Options and Install Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Sets build options for TDE2E, including installation flags and include paths. If static libraries are being installed, it generates pkg-config files and installs CMake targets. ```cmake set(TDE2E_ENABLE_INSTALL ${TD_INSTALL_STATIC_LIBRARIES} CACHE BOOL "" FORCE) set(TDE2E_INSTALL_INCLUDES ${TD_E2E_ONLY} CACHE BOOL "" FORCE) add_subdirectory(tde2e) if (TD_E2E_ONLY) if (TD_INSTALL_STATIC_LIBRARIES) include(GeneratePkgConfig) generate_pkgconfig(tdutils "Telegram Library - Utils") generate_pkgconfig(tde2e "Telegram Library - E2E") install(EXPORT TdStaticTargets FILE tde2eStaticTargets.cmake NAMESPACE tde2e:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tde2e" ) endif() endif() ``` -------------------------------- ### Enable Installation Option Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/tdnet/CMakeLists.txt Defines a CMake option to control whether the tdnet library should be installed. Defaults to ON. ```cmake option(TDNET_ENABLE_INSTALL "Enable installation of the library." ON) ``` -------------------------------- ### Install Build Dependencies with Homebrew Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/ios/README.md Installs necessary build tools like gperf, cmake, and coreutils using Homebrew. ```bash brew install gperf cmake coreutils ``` -------------------------------- ### TDDB Library Installation Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/tddb/CMakeLists.txt Installs the TDDB library targets if the TDDB_ENABLE_INSTALL option is set to ON. ```cmake if (TDDB_ENABLE_INSTALL) install(TARGETS tddb EXPORT TdStaticTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) endif() ``` -------------------------------- ### Install Dependencies with vcpkg Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/uwp/README.md Installs necessary libraries like gperf, openssl, and zlib for UWP architectures using vcpkg. Ensure you are using the correct vcpkg commit. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg git checkout bc3512a509f9d29b37346a7e7e929f9a26e66c7e .\bootstrap-vcpkg.bat .\vcpkg.exe install gperf:x86-windows openssl:arm-uwp openssl:arm64-uwp openssl:x64-uwp openssl:x86-uwp zlib:arm-uwp zlib:arm64-uwp zlib:x64-uwp zlib:x86-uwp ``` -------------------------------- ### Install Extra Dependencies (Fedora) Source: https://github.com/d99kris/nchat/blob/master/doc/LOWMEMORY.md Installs PHP CLI, which is required for building on Fedora systems. ```bash sudo dnf install php-cli ``` -------------------------------- ### Install Theme from Source Source: https://github.com/d99kris/nchat/blob/master/README.md Copy theme files to the Nchat config directory when Nchat is not running. Ensure you copy all necessary theme files. ```bash cp themes/dracula/* ~/.config/nchat/ ``` -------------------------------- ### Set Installation Targets Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Defines lists of targets to be installed for shared and static library installations. This includes various TDLib components and their export configurations. ```cmake set(INSTALL_TARGETS tdjson TdJson) set(INSTALL_STATIC_TARGETS tdjson_static TdJsonStatic tdjson_private "${TD_CORE_PART_TARGETS}" tdcore tdmtproto tdclient TdStatic tdapi) ``` -------------------------------- ### Enable Installation Option Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/tdactor/CMakeLists.txt Defines a CMake option to control whether the TD Actor library should be installed. Defaults to ON. ```cmake option(TDACTOR_ENABLE_INSTALL "Enable installation of the library." ON) ``` -------------------------------- ### Starting nchat Instances with Aliases Source: https://github.com/d99kris/nchat/blob/master/README.md Launch nchat instances for specific protocols using the previously defined aliases. ```bash telegram -s whatsapp -s ``` -------------------------------- ### Install Extra Dependencies (Debian/Ubuntu) Source: https://github.com/d99kris/nchat/blob/master/doc/LOWMEMORY.md Installs PHP CLI and Clang, which are required for building on Debian-based systems. ```bash sudo apt install php-cli clang ``` -------------------------------- ### Install Dependencies on CentOS 7 Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html Updates the system, installs SCL repositories, and installs development tools, libraries, and optionally Java for JNI targets. Sets CMake to cmake3. ```bash yum update -y yum install -y centos-release-scl-rh epel-release yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++ yum install -y gcc-c++ make git zlib-devel openssl-devel php gperf cmake3 ``` ```bash yum install -y java-11-openjdk-devel ``` -------------------------------- ### Install nchat dependencies using make.sh Source: https://github.com/d99kris/nchat/blob/master/README.md Install necessary dependencies for building nchat from source using the provided make.sh script. ```bash ./make.sh deps ``` -------------------------------- ### nchat Configuration File Example Source: https://github.com/d99kris/nchat/blob/master/README.md Default content of the app.conf configuration file, showing various application settings. ```ini assert_abort=0 attachment_prefetch=1 attachment_send_type=1 cache_enabled=1 cache_read_only=0 clipboard_copy_command= clipboard_has_image_command= clipboard_paste_command= clipboard_paste_image_command= coredump_enabled=0 downloads_dir= emoji_list_all=0 link_send_preview=1 logdump_enabled=0 mentions_quoted=1 message_delete=1 proxy_host= proxy_pass= proxy_port= proxy_user= timestamp_iso=0 use_pairing_code=0 use_qr_terminal=0 version_used= ``` -------------------------------- ### Install Shared Library Source: https://github.com/d99kris/nchat/blob/master/lib/wmchat/go/CMakeLists.txt Installs the built shared Go library to the appropriate system directory if HAS_STATICGOLIB is not set. This makes the library available for use by other applications. ```cmake if (NOT HAS_STATICGOLIB) install(FILES ${OUTPUT_DIR}/${LIB} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() ``` -------------------------------- ### Install Package Configuration Files Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Installs the main package configuration file (TdConfig.cmake) and the version file (TdConfigVersion.cmake) to the CMake package installation directory. This enables projects to find TDLib using `find_package(Td)`. ```cmake install(FILES "TdConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/TdConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Td" ) ``` -------------------------------- ### Build and Install nchat using make.sh Source: https://github.com/d99kris/nchat/blob/master/README.md Build and install nchat from source using the make.sh script, which is supported on various Linux distributions and macOS. ```bash ./make.sh ``` -------------------------------- ### Install Dependencies on FreeBSD Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html Upgrades packages and installs Git, gperf, PHP, CMake, and optionally OpenJDK for JNI targets. ```bash pkg upgrade pkg install -y git gperf php83 cmake ``` ```bash pkg install -y openjdk21 ``` -------------------------------- ### Install TD-SQLite Library Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/sqlite/CMakeLists.txt Configures the installation of the tdsqlite library when `TDSQLITE_ENABLE_INSTALL` is enabled. It specifies the destination directories for the library and archive files. ```cmake if (TDSQLITE_ENABLE_INSTALL) install(TARGETS tdsqlite EXPORT TdStaticTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) endif() ``` -------------------------------- ### Install TDLib Dependencies with vcpkg Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/csharp/README.md Installs necessary dependencies like gperf, openssl, and zlib for TDLib using vcpkg. Ensure vcpkg is cloned and bootstrapped before running. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg git checkout bc3512a509f9d29b37346a7e7e929f9a26e66c7e .\bootstrap-vcpkg.bat .\vcpkg.exe install gperf:x64-windows gperf:x86-windows openssl:x64-windows openssl:x86-windows zlib:x64-windows zlib:x86-windows ``` -------------------------------- ### Project Initialization and Go Version Check Source: https://github.com/d99kris/nchat/blob/master/lib/sgchat/go/CMakeLists.txt Initializes the CMake project and checks the installed Go version. The Go version is captured for potential use in build logic. ```cmake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(libcgosg) # Check Golang version execute_process(COMMAND bash "-c" "go version | cut -c14- | cut -d' ' -f1 | tr -d '\n'" OUTPUT_VARIABLE GO_VERSION) message(STATUS "Go version ${GO_VERSION}.") set(CUSTOM_GO_FLAGS -modcacherw -buildvcs=false) ``` -------------------------------- ### CMake Example Declarations Source: https://github.com/d99kris/nchat/blob/master/lib/ncutil/ext/clip/examples/CMakeLists.txt Calls the 'add_example' function to define build targets for several example applications. Each call compiles a corresponding C++ source file and links it with the Clip library. ```cmake add_example(copy) add_example(helloworld) add_example(int_format) add_example(paste) add_example(put_image) add_example(show_image) ``` -------------------------------- ### Install Homebrew and Dependencies on macOS Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html Installs Homebrew, gperf, CMake, OpenSSL, and optionally OpenJDK for JNI targets. ```bash xcode-select --install /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install gperf cmake openssl ``` ```bash brew install openjdk ``` -------------------------------- ### Install Dependencies on Debian/Ubuntu Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html Updates package lists and installs build tools, development libraries, and optionally OpenJDK and Clang/LLVM for JNI targets. ```bash apt-get update apt-get upgrade apt-get install -y make git zlib1g-dev libssl-dev gperf php-cli cmake ``` ```bash apt-get install -y default-jdk ``` ```bash apt-get install -y clang-14 libc++14-dev libc++abi14-dev ``` -------------------------------- ### Build TDLib for 64-bit .NET with CMake Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/csharp/README.md Configures and builds the 64-bit TDLib for .NET integration using CMake and vcpkg toolchain. This command should be run from the csharp example directory. ```bash cd .. mkdir build64 cd build64 cmake -A x64 -DTD_ENABLE_DOTNET=ON -DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake ../../.. cmake --build . --config Release cmake --build . --config Debug ``` -------------------------------- ### TDLib Build Script Commands Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html This snippet outlines the sequence of shell commands for cloning TDLib, setting up vcpkg, and installing dependencies. It handles different build configurations and target platforms. ```shell commands.push('git clone https://github.com/tdlib/td.git'); commands.push('cd td'); // commands.push('git checkout v1.8.0'); if (use_vcpkg) { commands.push('git clone https://github.com/Microsoft/vcpkg.git'); commands.push('cd vcpkg'); commands.push('git checkout bc3512a509f9d29b37346a7e7e929f9a26e66c7e'); commands.push(local + 'bootstrap-vcpkg.bat'); if (target === 'C++/CX') { commands.push(local + 'vcpkg.exe install gperf:x86-windows openssl:arm-uwp openssl:arm64-uwp openssl:x64-uwp openssl:x86-uwp zlib:arm-uwp zlib:arm64-uwp zlib:x64-uwp zlib:x86-uwp'); } else { if (build_64bit) { commands.push(local + 'vcpkg.exe install gperf:x64-windows openssl:x64-windows zlib:x64-windows'); } else { commands.push(local + 'vcpkg.exe install gperf:x86-windows openssl:x86-windows zlib:x86-windows'); } } commands.push('cd ..'); } ``` -------------------------------- ### Build TDLib with CMake Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/README.md Basic steps to build TDLib using CMake. Ensure all dependencies are installed before running these commands. ```bash mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release .. cmake --build . ``` -------------------------------- ### Install nchat on Arch Linux using AUR Source: https://github.com/d99kris/nchat/blob/master/README.md Install the latest git version or the stable release of nchat on Arch Linux using the AUR helper 'yay'. ```bash yay -S nchat-git ``` ```bash yay -S nchat ``` -------------------------------- ### Build TDLib for 32-bit .NET with CMake Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/csharp/README.md Configures and builds the 32-bit TDLib for .NET integration using CMake and vcpkg toolchain. This command should be run from the csharp example directory. ```bash cd /example/csharp mkdir build cd build cmake -A Win32 -DTD_ENABLE_DOTNET=ON -DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake ../../.. cmake --build . --config Release cmake --build . --config Debug ``` -------------------------------- ### Using Pairing Code for Authentication Source: https://github.com/d99kris/nchat/blob/master/README.md Set the USE_PAIRING_CODE environment flag to use authentication or pairing codes instead of scanning a QR code during setup. ```bash USE_PAIRING_CODE=1 nchat -s ``` -------------------------------- ### Add Example Executable Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/tdactor/CMakeLists.txt Adds an executable target named 'example' using 'example/example.cpp'. This is only done if cross-compiling is not enabled. The executable is linked privately against 'tdactor'. ```cmake if (NOT CMAKE_CROSSCOMPILING) add_executable(example example/example.cpp) target_link_libraries(example PRIVATE tdactor) endif() ``` -------------------------------- ### Analyze Core Dump with gdb (Manual Linux) Source: https://github.com/d99kris/nchat/blob/master/doc/DEBUGGING.md Open a core dump file with gdb when coredumpctl is not available. This example assumes the core dump is in the current directory. ```bash gdb $(which nchat) core ``` -------------------------------- ### Get Example Anchor by Language Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html This JavaScript function generates an anchor string for code examples based on the selected programming language. It maps language names to corresponding anchor IDs. ```javascript function getExampleAnchor(language) { switch (language) { case 'Python': case 'JavaScript': case 'Go': case 'Java': case 'Kotlin': case 'Swift': case 'Objective-C': case 'Dart': case 'Rust': case 'Erlang': case 'PHP': case 'Lua': case 'Ruby': case 'Crystal': case 'Haskell': case 'Nim': case 'Clojure': case 'D': case 'Elixir': case 'Vala': case 'C': case 'Assembly': case 'G': return language.toLowerCase(); case 'Object Pascal': return 'object-pascal'; case 'C#': return 'csharp'; case 'C++': return 'cxx'; default: return 'other'; } } ``` -------------------------------- ### Basic Database Operations Source: https://github.com/d99kris/nchat/blob/master/lib/ncutil/ext/sqlite_modern_cpp/README.md Demonstrates creating a database, creating a table, inserting data with different types, selecting data with a condition, and counting records. Includes examples of binding values and extracting single/multiple column results. ```c++ #include #include using namespace sqlite; using namespace std; int main() { try { // creates a database file 'dbfile.db' if it does not exists. database db("dbfile.db"); // executes the query and creates a 'user' table db << "create table if not exists user (" " _id integer primary key autoincrement not null," " age int," " name text," " weight real" ");"; // inserts a new user record. // binds the fields to '?' . // note that only types allowed for bindings are : // int ,long, long long, float, double // string , u16string // sqlite3 only supports utf8 and utf16 strings, you should use std::string for utf8 and std::u16string for utf16. // note that u"my text" is a utf16 string literal of type char16_t * . db << "insert into user (age,name,weight) values (?,?,?);" << 20 << u"bob" << 83.25; int age = 21; float weight = 68.5; string name = "jack"; db << u"insert into user (age,name,weight) values (?,?,?);" // utf16 query string << age << name << weight; cout << "The new record got assigned id " << db.last_insert_rowid() << endl; // slects from user table on a condition ( age > 18 ) and executes // the lambda for each row returned . db << "select age,name,weight from user where age > ? ;" << 18 >> [&](int age, string name, double weight) { cout << age << ' ' << name << ' ' << weight << endl; }; // selects the count(*) from user table // note that you can extract a single culumn single row result only to : int,long,long,float,double,string,u16string int count = 0; db << "select count(*) from user" >> count; cout << "cout : " << count << endl; // you can also extract multiple column rows db << "select age, name from user where _id=1;" >> tie(age, name); cout << "Age = " << age << ", name = " << name << endl; // this also works and the returned value will be automatically converted to string string str_count; db << "select count(*) from user" >> str_count; cout << "scount : " << str_count << endl; } catch (exception& e) { cout << e.what() << endl; } } ``` -------------------------------- ### Copy Build Instructions Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html Copies the generated build commands to the clipboard and provides visual feedback on success or failure. ```javascript function copyBuildInstructions() { var text = document.getElementById('buildCommands').innerText; function resetButtonState (state) { document.getElementById('copyBuildCommandsButton').classList.remove(state); document.getElementById('copyBuildCommandsText').innerText = "Copy"; } navigator.clipboard.writeText(text).then(result => { document.getElementById('copyBuildCommandsButton').classList.add('success'); document.getElementById('copyBuildCommandsText').innerText = "Copied!"; setTimeout(() => resetButtonState('success'), 5000); }, error => { document.getElementById('copyBuildCommandsButton').classList.add('fail'); document.getElementById('copyBuildCommandsText').innerText = "Couldn't copy :("; setTimeout(() => resetButtonState('fail'), 5000); }) } ``` -------------------------------- ### GPERF Executable Check and Setup Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/tdutils/generate/CMakeLists.txt Finds the gperf executable and sets up variables for generating MIME type and extension lookup tables. This block is skipped if cross-compiling. ```cmake if (NOT CMAKE_CROSSCOMPILING) find_program(GPERF_EXECUTABLE gperf) if (NOT GPERF_EXECUTABLE) message(FATAL_ERROR "Could NOT find gperf. Add path to gperf executable to PATH environment variable or specify it manually using GPERF_EXECUTABLE option, i.e. 'cmake -DGPERF_EXECUTABLE:FILEPATH=""'.") endif() set(GPERF_FILES ${CMAKE_CURRENT_SOURCE_DIR}/auto/mime_type_to_extension.gperf ${CMAKE_CURRENT_SOURCE_DIR}/auto/extension_to_mime_type.gperf ) set(GPERF_GEN_SOURCE generate_mime_types_gperf.cpp) add_executable(generate_mime_types_gperf ${GPERF_GEN_SOURCE}) add_custom_command( OUTPUT ${GPERF_FILES} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND generate_mime_types_gperf mime_types.txt ${GPERF_FILES} DEPENDS generate_mime_types_gperf mime_types.txt ) set(MIME_TYPE_TO_EXTENSION_CMD ${GPERF_EXECUTABLE} -m100 --output-file=auto/mime_type_to_extension.cpp auto/mime_type_to_extension.gperf) add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/auto/mime_type_to_extension.cpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ${MIME_TYPE_TO_EXTENSION_CMD} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/auto/mime_type_to_extension.gperf ) set(EXTENSION_TO_MIME_TYPE_CMD ${GPERF_EXECUTABLE} -m100 --output-file=auto/extension_to_mime_type.cpp auto/extension_to_mime_type.gperf) add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/auto/extension_to_mime_type.cpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ${EXTENSION_TO_MIME_TYPE_CMD} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/auto/extension_to_mime_type.gperf ) endif() ``` -------------------------------- ### Install nchat on macOS using Homebrew Source: https://github.com/d99kris/nchat/blob/master/README.md Install the stable release of nchat using the Homebrew package manager. Optionally, disable specific protocols during installation. ```bash brew tap d99kris/nchat brew install nchat ``` ```bash brew install nchat --without-telegram ``` -------------------------------- ### Prepare Theme Directories Source: https://github.com/d99kris/nchat/blob/master/themes/templates/iterm2-color-schemes/README.md Navigate to the iTerm2-Color-Schemes directory and create necessary subdirectories for nchat themes. ```bash cd iTerm2-Color-Schemes mkdir -p nchat-color nchat-usercolor cd tools ``` -------------------------------- ### Install TDClient Headers Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Installs the header files for the TDClient interface when static libraries are being installed. This makes the TDClient API accessible to applications linking against the static TDLib. ```cmake if (TD_INSTALL_STATIC_LIBRARIES) # Install tdclient: install(FILES td/telegram/Client.h td/telegram/Log.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/td/telegram") endif() ``` -------------------------------- ### Install Exported Targets for Static Libraries Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Installs the CMake export file for TDLib static libraries. This enables other projects to find and link against the installed static libraries. ```cmake if (TD_INSTALL_STATIC_LIBRARIES) install(EXPORT TdStaticTargets FILE TdStaticTargets.cmake NAMESPACE Td:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Td" ) endif() ``` -------------------------------- ### Install Exported Targets for Shared Libraries Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Installs the CMake export file for TDLib shared libraries. This allows other projects to find and use the installed shared libraries. ```cmake if (TD_INSTALL_SHARED_LIBRARIES) install(EXPORT TdTargets FILE TdTargets.cmake NAMESPACE Td:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Td" ) endif() ``` -------------------------------- ### Install Tdapi Headers Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Installs the Tdapi header files, including TlObject.h and the generated td_api headers, when static libraries are installed. This is crucial for applications interacting with the TDLib API. ```cmake if (TD_INSTALL_STATIC_LIBRARIES) # Install tdapi: install(FILES td/tl/TlObject.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/td/tl") install(FILES "${TL_TD_AUTO_INCLUDE_DIR}/td/telegram/td_api.h" "${TL_TD_AUTO_INCLUDE_DIR}/td/telegram/td_api.hpp" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/td/telegram") endif() ``` -------------------------------- ### Install TDJSON Headers Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Installs the necessary header files for the TDJSON interface, both for shared and static library installations. This ensures that applications using TDJSON can include the required headers. ```cmake if (TD_INSTALL_SHARED_LIBRARIES OR TD_INSTALL_STATIC_LIBRARIES) # Install tdjson/tdjson_static: install(FILES ${TD_JSON_HEADERS} "${CMAKE_CURRENT_BINARY_DIR}/td/telegram/tdjson_export.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/td/telegram") endif() ``` -------------------------------- ### Install Windows DLLs for VCPKG Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Installs DLL files for the current configuration to the installation bin directory when using MSVC and VCPKG toolchain. This is specific to Windows builds managed by VCPKG. ```cmake if (MSVC AND VCPKG_TOOLCHAIN) install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$/" DESTINATION "${CMAKE_INSTALL_BINDIR}" FILES_MATCHING PATTERN "*.dll") endif() ``` -------------------------------- ### Prepared Statement Usage Source: https://github.com/d99kris/nchat/blob/master/lib/ncutil/ext/sqlite_modern_cpp/README.md Demonstrates creating, binding values to, executing, and resetting prepared statements for potential performance gains with complex or frequently used queries. ```c++ database db(":memory:"); // if you use << on a sqlite::database you get a prepared statment back // this will not be executed till it gets destroyed or you execute it explicitly auto ps = db << "select a,b from table where something = ? and anotherthing = ?"; // get a prepared parsed and ready statment // first if needed bind values to it ps << 5; int tmp = 8; ps << tmp; // now you can execute it with `operator>>` or `execute()`. // If the statement was executed once it will not be executed again when it goes out of scope. // But beware that it will execute on destruction if it wasn't executed! ps >> [&](int a,int b){ ... }; // after a successfull execution the statment needs to be reset to be execute again. This will reset the bound values too! ps.reset(); // If you dont need the returned values you can execute it like this ps.execute(); // the statment will not be reset! // there is a convinience operator to execute and reset in one go ps++; // To disable the execution of a statment when it goes out of scope and wasn't used ps.used(true); // or false if you want it to execute even if it was used // Usage Example: auto ps = db << "insert into complex_table_with_lots_of_indices values (?,?,?)"; int i = 0; while( i < 100000 ){ ps << long_list[i++] << long_list[i++] << long_list[i++]; ps++; } ``` -------------------------------- ### JNI Example Build Configuration Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html This snippet configures the build process for Java Native Interface (JNI) targets. It sets up CMake with JNI-specific options and vcpkg toolchain file if applicable. ```shell if (target === 'JNI') { commands.push('cd example/java'); commands.push(use_powershell ? 'Remove-Item build -Force -Recurse -ErrorAction SilentlyContinue' : 'rm -rf build'); commands.push('mkdir build'); commands.push('cd build'); cmake_init_options = getBacicCmakeInitOptions(); if (jni_install_dir) { cmake_init_options.push('-DCMAKE_INSTALL_PREFIX:PATH=' + jni_install_dir); } if (use_vcpkg) { cmake_init_options.push('-DCMAKE_TOOLCHAIN_FILE:FILEPATH=../../../vcpkg/scripts/buildsystems/vcpkg.cmake'); } var is_alpine = os_linux && linux_distro === 'Alpine'; var resolve_path = use_powershell ? 'Resolve-Path' : (os_mac ? 'greadlink -e' : (is_alpine || ``` -------------------------------- ### Build nchat using CMake Source: https://github.com/d99kris/nchat/blob/master/README.md Commands to create a build directory, navigate into it, configure the build with CMake, and then compile the project. ```bash mkdir -p build && cd build && cmake .. && make -s ``` -------------------------------- ### Install Static Libraries Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Installs the static TDLib libraries and their associated header files. This is conditional on TD_INSTALL_STATIC_LIBRARIES. ```cmake if (TD_INSTALL_STATIC_LIBRARIES) install(TARGETS ${INSTALL_STATIC_TARGETS} EXPORT TdStaticTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) endif() ``` -------------------------------- ### Initialize Build Configuration Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html This JavaScript function initializes the build configuration based on URL parameters or browser history state. It sets up language and OS selection options. ```javascript function onLoad(initial) { var url = new URL(window.location.href); var language = url.searchParams.get('language'); if (language === 'csharp') { language = 'c#'; } else if (language === 'cxx') { language = 'c++'; } else if (!language) { language = ''; } var language_options = document.getElementById('languageSelect').options; for (var i = 0; i < language_options.length; i++) { language_options[i].selected = language_options[i].text.toLowerCase() === language.toLowerCase(); } onLanguageChanged(initial || !history.state); } ``` -------------------------------- ### C++ Serialization Example Source: https://github.com/d99kris/nchat/blob/master/lib/ncutil/ext/cereal/README.md Demonstrates how to serialize custom C++ data structures using cereal's binary archive. Includes definitions for MyRecord and SomeData, and shows how to save data to a binary file. ```cpp #include #include #include #include struct MyRecord { uint8_t x, y; float z; template void serialize( Archive & ar ) { ar( x, y, z ); } }; struct SomeData { int32_t id; std::shared_ptr> data; template void save( Archive & ar ) const { ar( data ); } template void load( Archive & ar ) { static int32_t idGen = 0; id = idGen++; ar( data ); } }; int main() { std::ofstream os("out.cereal", std::ios::binary); cereal::BinaryOutputArchive archive( os ); SomeData myData; archive( myData ); return 0; } ``` -------------------------------- ### Link Installed TDLib in CMake Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/README.md Find an installed TDLib package in your CMake project and link against the static library. ```cmake find_package(Td 1.8.64 REQUIRED) target_link_libraries(YourTarget PRIVATE Td::TdStatic) ``` -------------------------------- ### Database Backup with SQLite Functions Source: https://github.com/d99kris/nchat/blob/master/lib/ncutil/ext/sqlite_modern_cpp/README.md Demonstrates how to perform a database backup using SQLite's built-in backup functions. Ensure the backup database is opened before initiating the backup process. ```c++ try { database backup("backup"); //Open the database file we want to backup to auto con = db.connection(); // get a handle to the DB we want to backup in our scope 1. Basic Database Operations This library is a header-only library, so you just need to include the header file and you are ready to go. ```c++ #include using namespace sqlite; int main() { try { // creates a database file 'dbfile.db' if it does not exists database db("dbfile.db"); // executes the query and creates a 'user' table db << "create table if not exists user (_id integer primary key autoincrement not null, age int, name text, weight real);" ; // insert some data db << "insert into user (age,name,weight) values (?,?,?);" << 20 << "bob" << 83.25f; db << "insert into user (age,name,weight) values (?,?,?);" << 21 << "jack" << 68.5; // select data db << "select age,name,weight from user where age between ? and ?;" << 20 << 21 >> [](int age, std::string name, double weight) { std::cout << "age:" << age << " name:" << name << " weight:" << weight << std::endl; }; // more queries ... } catch (exception& e) { std::cerr << "Error: " << e.what() << std::endl; } return 0; } ``` ``` -------------------------------- ### Set Install Library Directory Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/tdactor/CMakeLists.txt Sets the default installation directory for libraries if CMAKE_INSTALL_LIBDIR is not already defined. Defaults to 'lib'. ```cmake if (NOT DEFINED CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR "lib") endif() ``` -------------------------------- ### Get Callstacks with lldb (macOS) Source: https://github.com/d99kris/nchat/blob/master/doc/DEBUGGING.md Within lldb, use 'bt all' to get callstacks for all threads and 'quit' to exit the debugger. ```bash bt all quit ``` -------------------------------- ### Configure Static Go Library Feature Source: https://github.com/d99kris/nchat/blob/master/CMakeLists.txt Enables building a static Go library. Defaults to ON. ```cmake # Feature - Static Go library option(HAS_STATICGOLIB "Static Go" ON) message(STATUS "Static Go: ${HAS_STATICGOLIB}") ``` -------------------------------- ### TDLib Naming and Installation Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/CMakeLists.txt Sets the TDLib name and filename based on the library linking type and installs the shared library if applicable. ```cmake if(LIBRARY_LINKING_TYPE STREQUAL "SHARED") set(TDLIBNAME "tdclientshared") set(TDLIBFILENAME "libtdclientshared${CMAKE_SHARED_LIBRARY_SUFFIX}") install(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TDLIBFILENAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) else() set(TDLIBNAME "tdclient") endif() ``` -------------------------------- ### Install Shared Libraries Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Installs the shared TDLib libraries and their associated files to the appropriate directories based on CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_BINDIR. This is conditional on TD_INSTALL_SHARED_LIBRARIES. ```cmake if (TD_INSTALL_SHARED_LIBRARIES) install(TARGETS ${INSTALL_TARGETS} EXPORT TdTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) endif() ``` -------------------------------- ### Install TD Actor Library Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/tdactor/CMakeLists.txt Installs the 'tdactor' target if TDACTOR_ENABLE_INSTALL is ON. It specifies the destination directories for the library and archive files based on CMAKE_INSTALL_LIBDIR. ```cmake if (TDACTOR_ENABLE_INSTALL) install(TARGETS tdactor EXPORT TdStaticTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) endif() ``` -------------------------------- ### Force Building libsignal_ffi from Source Source: https://github.com/d99kris/nchat/blob/master/doc/SIGNAL.md Use this command to explicitly build the libsignal_ffi library from source, bypassing the pre-built binary download. This is necessary if the download fails or is unavailable for your platform. ```bash NCHAT_CMAKEARGS="-DHAS_SIGNAL=ON -DDOWNLOAD_LIBSIGNAL=OFF" ./make.sh build ``` -------------------------------- ### Get Callstacks with gdb (Linux) Source: https://github.com/d99kris/nchat/blob/master/doc/DEBUGGING.md Within gdb, use 'thread apply all bt' to get callstacks for all threads and 'quit' to exit the debugger. ```bash thread apply all bt quit ``` -------------------------------- ### Install Dependencies on Alpine Linux Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html Updates package lists and installs essential build tools, development libraries, and optionally OpenJDK for JNI targets. ```bash apk update apk upgrade apk add alpine-sdk linux-headers git zlib-dev openssl-dev gperf php cmake ``` ```bash apk add openjdk8 ``` -------------------------------- ### TDLib Build Configuration Options Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html These are interactive prompts for configuring the TDLib build process. They allow users to select shell applications, host architecture, and target bitness. ```text Choose which shell application you want to use for building: PowerShell mintty/Bash Choose which shell application you want to use for building: tcsh/csh Bash Choose host architecture: Apple silicon Intel Choose for which bitness you want to build TDLib: 32 64 Check this if you have less than 4 GB of RAM Build from root user (not recommended) ``` -------------------------------- ### Go Library Build Configuration Source: https://github.com/d99kris/nchat/blob/master/lib/sgchat/go/CMakeLists.txt Configures the build for the Go library, defining target name, GOPATH, source files, and the output library name. ```cmake # Build Go library / C archive set(TARGET cgosg) set(GOPATH ${OUTPUT_DIR}) set(SRCS gosg.go cgosg.go go.mod go.sum) file(GLOB_RECURSE EXT_SRCS ext/*.go) list(APPEND SRCS ${EXT_SRCS}) set(LIB "libcgosg${CMAKE_SHARED_LIBRARY_SUFFIX}") ``` -------------------------------- ### Build TDLib SDK for UWP Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/example/uwp/README.md Builds the TDLib SDK for Universal Windows Platform using the provided build script. Specify the path to your vcpkg installation using the -vcpkg_root argument. The build process may take several hours. ```powershell powershell -ExecutionPolicy ByPass .\build.ps1 -vcpkg_root C:\vcpkg ``` -------------------------------- ### Install JNI Object Header Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/CMakeLists.txt Installs the tl_jni_object.h header file when the JNI interface is enabled. This header is required for integrating TDLib with Java applications via JNI. ```cmake if (TD_ENABLE_JNI) install(FILES td/tl/tl_jni_object.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/td/tl") endif() ``` -------------------------------- ### Database Configuration with Flags Source: https://github.com/d99kris/nchat/blob/master/lib/ncutil/ext/sqlite_modern_cpp/README.md Shows how to configure SQLite database connections using a `sqlite_config` object to specify open flags (e.g., READONLY) and encoding (e.g., UTF16). ```c++ sqlite_config config; config.flags = OpenFlags::READONLY; database db("some_db", config); int a; // Now you can only read from db auto ps = db << "select a from table where something = ? and anotherthing = ?" >> a; config.flags = OpenFlags::READWRITE | OpenFlags::CREATE; // This is the default config.encoding = Encoding::UTF16; // The encoding is respected only if you create a new database database db2("some_db2", config); // If some_db2 didn't exists before, it will be created with UTF-16 encoding. ``` -------------------------------- ### Prepare Cross-Compiling (Split Source) Source: https://github.com/d99kris/nchat/blob/master/doc/LOWMEMORY.md Prepares the source code for cross-compiling by splitting the Telegram client library source. This step is optional and reduces RAM requirements during the build. ```bash cmake --build . --target prepare_cross_compiling cd ../lib/tgchat/ext/td ; php SplitSource.php ; cd - ``` -------------------------------- ### Install Dependencies on CentOS 8/Stream 9 Source: https://github.com/d99kris/nchat/blob/master/lib/tgchat/ext/td/build.html Updates the system and installs development tools, libraries, and optionally Java for JNI targets. Enables the CodeReady Builder repository for gperf. ```bash dnf update -y dnf --enablerepo=crb install -y gperf dnf install -y gcc-c++ make git zlib-devel openssl-devel php cmake ``` ```bash dnf install -y java-11-openjdk-devel ```