<commit_before>module Stellerator.View.Cartridges exposing (page)

import Css exposing (..)
import Css.Global as Sel exposing (children, global, selector)
import Dos exposing (Color(..))
import Html.Styled exposing (..)
import Html.Styled.Attributes as A
import Html.Styled.Events as E
import Html.Styled.Keyed as Keyed
import Json.Decode as Decode
import List.Extra as LE
import Stellerator.Model
    exposing
        ( AudioEmulation(..)
        , Cartridge
        , CartridgeViewMode(..)
        , ChangeCartridgeMsg(..)
        , CpuEmulation(..)
        , Media(..)
        , Model
        , Msg(..)
        , TvMode(..)
        , cartridgesMatchingSearch
        )
import Stellerator.View.Form as Form



-- COMMON


onKeyDown : (Int -> Msg) -> Attribute Msg
onKeyDown tagger =
    let
        t m =
            case m of
                None ->
                    ( m, False )

                _ ->
                    ( m, True )
    in
    E.preventDefaultOn "keydown" (Decode.map t <| Decode.map tagger E.keyCode)


ifHaveSelection : Model -> a -> a -> a
ifHaveSelection model a b =
    case model.currentCartridgeHash of
        Just _ ->
            a

        Nothing ->
            b


cartSelected : Cartridge -> Maybe String -> Bool
cartSelected cartridge hash =
    Maybe.map ((==) cartridge.hash) hash |> Maybe.withDefault False


ifCartSelected : Cartridge -> Maybe String -> a -> a -> a
ifCartSelected cartridge hash a b =
    if cartSelected cartridge hash then
        a

    else
        b


keyboardHandler : Model -> Int -> Msg
keyboardHandler model code =
    case code of
        38 ->
            Maybe.map SelectPreviousCartridgeMatchingSearch model.currentCartridgeHash
                |> Maybe.withDefault SelectLastCartridgeMatchingSearch

        40 ->
            Maybe.map SelectNextCartridgeMatchingSearch model.currentCartridgeHash
                |> Maybe.withDefault SelectFirstCartridgeMatchingSearch

        _ ->
            None


settingsItems : Model -> Cartridge -> List (Html Msg)
settingsItems model cart =
    let<commit_msg>Add key combo (ctr-d) for deleting the current cartridge.<commit_after>module Stellerator.View.Cartridges exposing (page)

import Css exposing (..)
import Css.Global as Sel exposing (children, global, selector)
import Dos exposing (Color(..))
import Html.Styled exposing (..)
import Html.Styled.Attributes as A
import Html.Styled.Events as E
import Html.Styled.Keyed as Keyed
import Json.Decode as Decode
import List.Extra as LE
import Stellerator.Model
    exposing
        ( AudioEmulation(..)
        , Cartridge
        , CartridgeViewMode(..)
        , ChangeCartridgeMsg(..)
        , CpuEmulation(..)
        , Media(..)
        , Model
        , Msg(..)
        , TvMode(..)
        , cartridgesMatchingSearch
        , selectionInSearchResults
        )
import Stellerator.View.Form as Form



-- COMMON


onKeyDown : (( Bool, Int ) -> Msg) -> Attribute Msg
onKeyDown tagger =
    let
        t m =
            case m of
                None ->
                    ( m, False )

                _ ->
                    ( m, True )
    in
    E.preventDefaultOn "keydown"
        (Decode.map2 Tuple.pair (Decode.field "ctrlKey" Decode.bool) (Decode.field "keyCode" Decode.int)
            |> Decode.map tagger
            |> Decode.map t
        )


ifHaveSelection : Model -> a -> a -> a
ifHaveSelection model a b =
    case model.currentCartridgeHash of
        Just _ ->
            a

        Nothing ->
            b


cartSelected : Cartridge -> Maybe String -> Bool
cartSelected cartridge hash =
    Maybe.map ((==) cartridge.hash) hash |> Maybe.withDefault False


ifCartSelected : Cartridge -> Maybe String -> a -> a -> a
ifCartSelected cartridge hash a b =
    if cartSelected cartridge hash then
        a

    else
        b


keyboardHandler : Model -> ( Bool, Int ) -> Msg
keyboardHandler model code =
    case code of
        ( False, 38 ) ->
            Maybe.map SelectPreviousCartridgeMatchingSearch model.currentCartridgeHash
                |> Maybe.withDefault SelectLastCartridgeMatchingSearch

        ( False, 40 ) ->
            Maybe.map SelectNextCartridgeMatchingSearch model.currentCartridgeHash
                |> Maybe.withDefault SelectFirstCartridgeMatchingSearch

        ( True, 68 ) ->
            Maybe.map DeleteCartridge (selectionInSearchResults model) |> Maybe.withDefault None

        _ ->
            None


settingsItems : Model -> Cartridge -> List (Html Msg)
settingsItems model cart =
    let
{'fraction_non_alphanumeric': 0.0881767955801105, 'fraction_numerical': 0.002430939226519337, 'mean_word_length': 2.0113107119095144, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4816556', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1246, 'n_words': 363}