Skip to content

Commit

Permalink
Ponysay
Browse files Browse the repository at this point in the history
Dodano funkcję do wyświetlania kucyków używając ponysay

Oryginalny ponysay wyświetlał błąd opisany w
erkin/ponysay#314
Więc ponysay brany jest z
https://github.com/Tonyl314/ponysay
  • Loading branch information
fpekal committed Nov 7, 2024
1 parent 93d29f4 commit 7922abb
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 13 deletions.
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
customPonysay = {
url = "github:Tonyl314/ponysay";
flake = false;
};
};

outputs =
{ nixpkgs, self }:
{ nixpkgs, customPonysay, self }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
libs = import ./nix/libs.nix { inherit pkgs customPonysay; };
in
{
devShells.x86_64-linux.default = (import ./nix/shell.nix) { inherit pkgs; };
apps.x86_64-linux.default = (import ./nix/app.nix) { inherit pkgs; };
devShells.x86_64-linux.default = (import ./nix/shell.nix) { inherit pkgs libs; };
apps.x86_64-linux.default = (import ./nix/app.nix) { inherit pkgs libs; };
};
}
4 changes: 1 addition & 3 deletions nix/app.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{ pkgs }:
{ pkgs, libs }:
let
libs = import ./libs.nix { inherit pkgs; };

package =
pkgs.stdenv.mkDerivation {
name = "pony";
Expand Down
8 changes: 6 additions & 2 deletions nix/libs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{ pkgs, customPonysay }:
{
nativeBuildInputs =
with pkgs; [
Expand All @@ -11,6 +11,10 @@

buildInputs =
with pkgs; [
sqlite
#ponysay # BROKEN
# Fix for this issue: https://github.com/erkin/ponysay/issues/314
(ponysay.overrideAttrs {
src = customPonysay;
})
];
}
7 changes: 2 additions & 5 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{ pkgs }:
let
libs = import ./libs.nix { inherit pkgs; };
in
{ pkgs, libs }:
pkgs.mkShell {
nativeBuildInputs = libs.nativeBuildInputs;
nativeBuildInputs = libs.nativeBuildInputs ++ libs.buildInputs;
}
3 changes: 3 additions & 0 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "db/db-connection.h"
#include "db/pony-loader.h"
#include "db/pony-saver.h"
#include "tui/ponysay.h"

std::string load_scheme() {
std::ifstream ifs("sql/make_scheme.sql");
Expand All @@ -16,6 +17,8 @@ std::string load_scheme() {
}

int main() {
ponysay("pinkiepie");

DbConnection db = open_db("file:pony.db");

sqlite3_exec(*db, load_scheme().c_str(), nullptr, nullptr, nullptr);
Expand Down
10 changes: 10 additions & 0 deletions src/tui/ponysay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "ponysay.h"

#include <iostream>

#include "../util.h"

void ponysay(const std::string& pony_name) {
std::string cmd = "ponysay -o -f " + pony_name;
std::cout << exec(cmd);
}
4 changes: 4 additions & 0 deletions src/tui/ponysay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
#include <string>

void ponysay(const std::string& pony_name);
21 changes: 21 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "util.h"

#include <cstdio>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
#include <array>

std::string exec(const std::string& cmd) {
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
while (fgets(buffer.data(), static_cast<int>(buffer.size()), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}
5 changes: 5 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include <string>

// Run linux command and return the stdout
std::string exec(const std::string& cmd);

0 comments on commit 7922abb

Please sign in to comment.